Normalizer.py 607 Bytes
Newer Older
1
2
3
4
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# @author: Tiago de Freitas Pereira <tiago.pereira@idiap.ch>

5
import numpy
6

7
def scale_factor(x, scale_factor=0.00390625):
8
9
10
    """
    Normalize a sample by a scale factor
    """
11
    return x * scale_factor
12
13


14
def mean_offset(x, mean_offset):
15
16
17
18
    """
    Normalize a sample by a mean offset
    """

19
20
    for i in range(len(mean_offset)):
        x[:, :, i] = x[:, :, i] - mean_offset[i]
21

22
    return x
23

24
def per_image_standarization(x):
25
    
26
27
    mean = numpy.mean(x)
    std = numpy.std(x)
28

29
    return (x-mean)/max(std, 1/numpy.sqrt(numpy.prod(x.shape)))
30