Skip to content

Commit ed8a2fe

Browse files
author
yxdragon
committed
fft
1 parent aadbd6d commit ed8a2fe

File tree

8 files changed

+82
-8
lines changed

8 files changed

+82
-8
lines changed

imagepy/core/engine/filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def process_one(plg, ips, src, img, para, callafter=None):
3030
TaskManager.add(plg)
3131
start = time()
3232
transint = '2int' in plg.note and ips.dtype in (np.uint8, np.uint16)
33-
transfloat = '2float' in plg.note and not ips.dtype in (np.float32, np.float64)
33+
transfloat = '2float' in plg.note and not ips.dtype in (np.complex128, np.float32, np.float64)
3434
if transint:
3535
buf = img.astype(np.int32)
3636
src = src.astype(np.int32)
@@ -53,7 +53,7 @@ def process_stack(plg, ips, src, imgs, para, callafter=None):
5353
TaskManager.add(plg)
5454
start = time()
5555
transint = '2int' in plg.note and ips.dtype in (np.uint8, np.uint16)
56-
transfloat = '2float' in plg.note and not ips.dtype in (np.float32, np.float64)
56+
transfloat = '2float' in plg.note and not ips.dtype in (np.complex128, np.float32, np.float64)
5757
if transint:
5858
buf = imgs[0].astype(np.int32)
5959
src = src.astype(np.int32)

imagepy/core/wraper/imageplus.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def get_img_type(imgs):
88
if imgs[0].dtype == np.int32:return '32-int'
99
if imgs[0].dtype == np.float32:return '32-float'
1010
if imgs[0].dtype == np.float64:return '64-float'
11+
if imgs[0].dtype == np.complex128:return 'complex'
1112

1213
class ImagePlus:
1314
"""ImagePlus: a class to make operation more flexible """

imagepy/menus/Image/Type/convert_plg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,5 @@ def run(self, ips, imgs, para = None):
163163
k = 255.0/(max(1e-10, maxv-minv))
164164
img64.append(imgs[i].astype(np.float64))
165165
ips.set_imgs(img64)
166-
166+
167167
plgs = [To8bit, ToRGB, '-', ToUint16, ToInt32, ToFloat32, ToFloat64]

imagepy/menus/Process/FFT/__init__.py

Whitespace-only changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import numpy as np
2+
from imagepy.core.engine import Simple, Filter
3+
from numpy.fft import fft2, ifft2, fftshift, ifftshift
4+
from imagepy import IPy
5+
6+
class FFT(Simple):
7+
title = 'FFT'
8+
note = ['8-bit', '16-bit', 'int', 'float']
9+
para = {'shift':True, 'slice':False}
10+
view = [(bool, 'shift', 'zero center'),
11+
(bool, 'slice', 'slices')]
12+
13+
def run(self, ips, imgs, para = None):
14+
if not para['slice']: imgs = [ips.img]
15+
shift = fftshift if para['shift'] else lambda x:x
16+
rst = []
17+
for i in range(len(imgs)):
18+
rst.append(shift(fft2(imgs[i])))
19+
self.progress(i, len(imgs))
20+
IPy.show_img(rst, '%s-fft'%ips.title)
21+
22+
class LogPower(Simple):
23+
title = 'Log Power'
24+
note = ['complex']
25+
para = {'slice':False, 'type':'float', 'log':2.718}
26+
view = [(float, 'log', (2,30), 3, 'log', ''),
27+
(list, 'type', ['uint8', 'int', 'float'], str, 'type', ''),
28+
(bool, 'slice', 'slices')]
29+
30+
def run(self, ips, imgs, para = None):
31+
if not para['slice']: imgs = [ips.img]
32+
tp = {'uint8':np.uint8, 'int':np.int32, 'float':np.float32}
33+
rst, tp = [], tp[para['type']]
34+
for i in range(len(imgs)):
35+
zs = np.log(np.abs(imgs[i]))
36+
zs /= np.log(para['log'])
37+
rst.append(zs.astype(tp))
38+
self.progress(i, len(imgs))
39+
IPy.show_img(rst, '%s-fft'%ips.title)
40+
41+
class IFFT(Simple):
42+
title = 'Inverse FFT'
43+
note = ['complex']
44+
para = {'shift':True, 'slice':False, 'type':'float'}
45+
view = [(list, 'type', ['uint8', 'int', 'float'], str, 'type', ''),
46+
(bool, 'shift', 'zero center'),
47+
(bool, 'slice', 'slices')]
48+
49+
def run(self, ips, imgs, para = None):
50+
if not para['slice']: imgs = [ips.img]
51+
shift = ifftshift if para['shift'] else lambda x:x
52+
tp = {'uint8':np.uint8, 'int':np.int32, 'float':np.float32}
53+
rst, tp = [], tp[para['type']]
54+
for i in range(len(imgs)):
55+
rst.append(ifft2(shift(ips.img)).astype(tp))
56+
self.progress(i, len(imgs))
57+
IPy.show_img(rst, '%s-ifft'%ips.title)
58+
59+
class Shift(Filter):
60+
title = 'Zero Center'
61+
note = ['complex']
62+
63+
def run(self, ips, snap, img, para = None):
64+
return fftshift(img)
65+
66+
class IShift(Filter):
67+
title = 'Zero Edge'
68+
note = ['complex']
69+
70+
def run(self, ips, snap, img, para = None):
71+
return ifftshift(img)
72+
73+
plgs = [FFT, IFFT, '-', Shift, IShift, LogPower]

imagepy/menus/Process/Hydrology/hydrology_plgs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ def run(self, ips, snap, img, para = None):
9999

100100
class ARidge(Filter):
101101
title = 'Active Ridge'
102-
note = ['8-bit', 'not_slice', 'auto_snap', 'not_channel']
102+
note = ['8-bit', 'not_slice', 'auto_snap', 'not_channel', 'req_roi']
103103

104104
para = {'sigma':1.0, 'ud':True, 'type':'white line'}
105-
view = [(float, (0,5), 1, 'sigma', 'sigma', 'pix'),
106-
(list, 'type', ['white line', 'gray line', 'white line on ori'], str, 'output', ''),
105+
view = [(float, 'sigma', (0,5), 1, 'sigma', 'pix'),
106+
(list, 'type', ['white line', 'gray line', 'white line on ori'], str, 'output', ''),
107107
(bool, 'ud', 'ascend')]
108108

109109
def run(self, ips, snap, img, para = None):

imagepy/menus/Process/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
catlog = ['Math', 'Binary', 'Filters', '-', 'Threshold', 'Hydrology', 'Features', 'Segment', 'repair_plg', '-', 'calculator_plg']
1+
catlog = ['Math', 'Binary', 'Filters', 'FFT', '-', 'Threshold', 'Hydrology', 'Features', 'Segment', 'repair_plg', '-', 'calculator_plg']

imagepy/ui/canvas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ def merge(self, img, back, M, O, mode, shape, win, lookup):
180180
if img.ndim == 2:
181181
rstarr = np.zeros(shape, dtype=img.dtype)
182182
my_transform(img, M, offset=O, output=rstarr, k=1, clip=False)
183+
if rstarr.dtype == np.complex128: rstarr = np.abs(rstarr)
183184
rstarr = lookup(rstarr)
184-
185185
if img.ndim == 3:
186186
rstarr = np.zeros((win[3], win[2], 3), dtype=img.dtype)
187187
for i in range(3):

0 commit comments

Comments
 (0)