88
99class Plugin (Simple ):
1010 title = 'Normalize'
11- note = ['8-bit' ,'16-bit' ,'float' , 'stack' ]
12- para = {'if3d ' : False , 'Sb' : False }
13- view = [(bool , 'if3d ' , '3D stack' ),
14- (bool , 'Sb ' , 'Subtract background' )]
11+ note = ['8-bit' ,'16-bit' ,'float' ]
12+ para = {'is3d ' : False , 'sb' : True }
13+ view = [(bool , 'is3d ' , '3D stack' ),
14+ (bool , 'sb ' , 'Subtract background' )]
1515
1616 def run (self , ips , imgs , para = None ):
17- imgs_ = np .array (imgs ).astype ('float64' ).transpose (1 ,2 ,0 )
18- if para ['if3d' ]:
19- if para ['Sb' ]:
20- imgs_ -= imgs_ .min ()
21- imgs_ = imgs_ / imgs_ .max ()
22- else :
23- if para ['Sb' ]:
24- for i in range (z ):
25- imgs_ [:,:,i ] -= imgs_ [:,:,i ].min ()
26- for i in range (z ):
27- imgs_ [:,:,i ] = imgs_ [:,:,i ] / imgs_ [:,:,i ].max ()
28- if imgs .dtype == np .uint8 :
29- imgs [:] = (255 * imgs_ ).astype (imgs .dtype ).transpose (2 ,0 ,1 )
30- elif imgs .dtype == np .uint16 :
31- imgs [:] = (65535 * imgs_ ).astype (imgs .dtype ).transpose (2 ,0 ,1 )
32- else :
33- imgs [:] = (imgs_ ).astype (imgs .dtype ).transpose (2 ,0 ,1 )
17+ lim = np .zeros ([len (imgs ), 2 ], dtype = imgs [0 ].dtype )
18+ dic = {np .uint8 :255 , np .uint16 :65535 , np .float32 :1 , np .float64 :1 }
19+
20+ IPy .set_info ('count range ...' )
21+ for i in range (len (imgs )):
22+ lim [i ] = imgs [i ].min (), imgs [i ].max ()
23+ self .progress (i , len (imgs ))
24+
25+ maxvalue = dic [imgs [0 ].dtype .type ]
26+ if not para ['sb' ]: lim [:,0 ] = 0
27+ rg = lim [:,0 ].min (), lim [:,1 ].max ()
28+ if para ['is3d' ]: lim [:] = rg
29+ IPy .set_info ('adjust range ...' )
30+ for i in range (len (imgs )):
31+ if para ['sb' ]: imgs [i ] -= lim [i ,0 ]
32+ np .multiply (imgs [i ], maxvalue / (lim [i ].ptp ()), out = imgs [i ], casting = 'unsafe' )
33+ self .progress (i , len (imgs ))
34+ ips .range = 0 , maxvalue
0 commit comments