Skip to content

Commit 43cd5c4

Browse files
author
yxdragon
committed
adjust
1 parent ca05867 commit 43cd5c4

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

imagepy/core/util/fileio.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
def show_img(img, title):
99
if isinstance(img, list):
1010
return IPy.show_img(img, title)
11-
# if img.dtype!=np.uint8 and img.ndim>2 and img.shape[2]!=3:
1211
if img.ndim>2 and img.shape[2]!=3:
1312
return IPy.show_img(img, title)
1413
if img.dtype==np.uint8 and img.ndim==3 and img.shape[2]==4:

imagepy/core/wraper/imageplus.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ def lookup(self, img=None):
178178

179179

180180
def swap(self):
181-
print(type(self.snap), type(self.imgs[self.cur]), self.cur)
182181
if self.snap is None:return
183182
if isinstance(self.imgs, list):
184183
self.snap, self.imgs[self.cur] = self.imgs[self.cur], self.snap

imagepy/menus/Image/Adjust/enhanceContrast_plg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import numpy as np
88

99
class Plugin(Filter):
10-
title = 'Enhance contrast'
10+
title = 'Enhance Contrast'
1111
note = ['all', 'auto_msk', 'auto_snap','preview']
12-
para = {'percentage': 0.3}
13-
view = [(float, 'percentage', (0,100), 4, 'Saturated pixels', '%')]
12+
para = {'percentage': 5}
13+
view = [(float, 'percentage', (0,100), 2, 'Saturated pixels', '%')]
1414

1515
def run(self, ips, snap, img, para = None):
16-
up, down = np.percentile(snap, (0, 100 - para['percentage']))
16+
up, down = np.percentile(snap, (para['percentage']/2, 100-para['percentage']/2))
1717
return exposure.rescale_intensity(snap, in_range=(up, down))

imagepy/menus/Image/Adjust/normalize_plg.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,27 @@
88

99
class 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

Comments
 (0)