back to iatexture

Function preproc3sigma

Synopse

The preproc3sigma function performs a pre-processing method called 3sigma.

  • g = preproc3sigma(f,roi)
    • Output
      • g: output image
      • roi: the region of interest
    • Input
      • f: ndarray: input image.

Description

The preproc3sigma function performs a pre-processing method called 3 sigma. It is equivalent to range the image into [mu-3sigma, mu+3sigma], where mu is the ROI mean and sigma the ROI standard deviation.

Function Code

 1 from ia636 import ianormalize
 2 import numpy as np
 3 
 4 def preproc3sigma(f,roi,rate=8):
 5     aux = f[roi]
 6     mu = np.mean(aux)
 7     sigma = np.std(aux,ddof=0)
 8 
 9     lower = np.round(mu-3*sigma)
10     upper = np.round(mu+3*sigma)
11     f[f<=lower] = lower
12     f[f>=upper] = upper
13     return ianormalize(f,[0,2**rate -1])

Example

 1 from preproc3sigma import preproc3sigma
 2 import ia636
 3 
 4 f = adread('cameraman.tif')
 5 roi = f>100
 6 mu = mean(f[roi])
 7 sigma = std(f[roi])
 8 lower = round(mu-3*sigma)
 9 upper = round(mu+3*sigma)
10 print f.min(),f.max()
11 print 'lower,upper',lower,upper
12 print len(argwhere(f<lower)),len(argwhere(f>upper)),size(f)
13 f[argwhere(f>upper)] = upper
14 print f.min(),f.max()
15 f[f<lower] = lower
16 
17 print f.min(),f.max()
18 print 'f.info',ia636.iaimginfo(f)
19 r = ia636.ianormalize(f,[0,255])
20 print 'r.info',ia636.iaimginfo(r)
21 result = preproc3sigma(f,roi)
22 print 'result.info',ia636.iaimginfo(result)
0 251
lower,upper 111.0 281.0
22285 0 65536
0 251
111 251
f.info <type 'numpy.ndarray'> (256, 256) uint8 111 251
r.info <type 'numpy.ndarray'> (256, 256) uint8 0 255
result.info <type 'numpy.ndarray'> (256, 256) uint8 0 255