Skip to content

Commit

Permalink
fft
Browse files Browse the repository at this point in the history
  • Loading branch information
yxdragon committed Mar 14, 2019
1 parent aadbd6d commit ed8a2fe
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 8 deletions.
4 changes: 2 additions & 2 deletions imagepy/core/engine/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def process_one(plg, ips, src, img, para, callafter=None):
TaskManager.add(plg)
start = time()
transint = '2int' in plg.note and ips.dtype in (np.uint8, np.uint16)
transfloat = '2float' in plg.note and not ips.dtype in (np.float32, np.float64)
transfloat = '2float' in plg.note and not ips.dtype in (np.complex128, np.float32, np.float64)
if transint:
buf = img.astype(np.int32)
src = src.astype(np.int32)
Expand All @@ -53,7 +53,7 @@ def process_stack(plg, ips, src, imgs, para, callafter=None):
TaskManager.add(plg)
start = time()
transint = '2int' in plg.note and ips.dtype in (np.uint8, np.uint16)
transfloat = '2float' in plg.note and not ips.dtype in (np.float32, np.float64)
transfloat = '2float' in plg.note and not ips.dtype in (np.complex128, np.float32, np.float64)
if transint:
buf = imgs[0].astype(np.int32)
src = src.astype(np.int32)
Expand Down
1 change: 1 addition & 0 deletions imagepy/core/wraper/imageplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def get_img_type(imgs):
if imgs[0].dtype == np.int32:return '32-int'
if imgs[0].dtype == np.float32:return '32-float'
if imgs[0].dtype == np.float64:return '64-float'
if imgs[0].dtype == np.complex128:return 'complex'

class ImagePlus:
"""ImagePlus: a class to make operation more flexible """
Expand Down
2 changes: 1 addition & 1 deletion imagepy/menus/Image/Type/convert_plg.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ def run(self, ips, imgs, para = None):
k = 255.0/(max(1e-10, maxv-minv))
img64.append(imgs[i].astype(np.float64))
ips.set_imgs(img64)

plgs = [To8bit, ToRGB, '-', ToUint16, ToInt32, ToFloat32, ToFloat64]
Empty file.
73 changes: 73 additions & 0 deletions imagepy/menus/Process/FFT/fft_plgs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import numpy as np
from imagepy.core.engine import Simple, Filter
from numpy.fft import fft2, ifft2, fftshift, ifftshift
from imagepy import IPy

class FFT(Simple):
title = 'FFT'
note = ['8-bit', '16-bit', 'int', 'float']
para = {'shift':True, 'slice':False}
view = [(bool, 'shift', 'zero center'),
(bool, 'slice', 'slices')]

def run(self, ips, imgs, para = None):
if not para['slice']: imgs = [ips.img]
shift = fftshift if para['shift'] else lambda x:x
rst = []
for i in range(len(imgs)):
rst.append(shift(fft2(imgs[i])))
self.progress(i, len(imgs))
IPy.show_img(rst, '%s-fft'%ips.title)

class LogPower(Simple):
title = 'Log Power'
note = ['complex']
para = {'slice':False, 'type':'float', 'log':2.718}
view = [(float, 'log', (2,30), 3, 'log', ''),
(list, 'type', ['uint8', 'int', 'float'], str, 'type', ''),
(bool, 'slice', 'slices')]

def run(self, ips, imgs, para = None):
if not para['slice']: imgs = [ips.img]
tp = {'uint8':np.uint8, 'int':np.int32, 'float':np.float32}
rst, tp = [], tp[para['type']]
for i in range(len(imgs)):
zs = np.log(np.abs(imgs[i]))
zs /= np.log(para['log'])
rst.append(zs.astype(tp))
self.progress(i, len(imgs))
IPy.show_img(rst, '%s-fft'%ips.title)

class IFFT(Simple):
title = 'Inverse FFT'
note = ['complex']
para = {'shift':True, 'slice':False, 'type':'float'}
view = [(list, 'type', ['uint8', 'int', 'float'], str, 'type', ''),
(bool, 'shift', 'zero center'),
(bool, 'slice', 'slices')]

def run(self, ips, imgs, para = None):
if not para['slice']: imgs = [ips.img]
shift = ifftshift if para['shift'] else lambda x:x
tp = {'uint8':np.uint8, 'int':np.int32, 'float':np.float32}
rst, tp = [], tp[para['type']]
for i in range(len(imgs)):
rst.append(ifft2(shift(ips.img)).astype(tp))
self.progress(i, len(imgs))
IPy.show_img(rst, '%s-ifft'%ips.title)

class Shift(Filter):
title = 'Zero Center'
note = ['complex']

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

class IShift(Filter):
title = 'Zero Edge'
note = ['complex']

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

plgs = [FFT, IFFT, '-', Shift, IShift, LogPower]
6 changes: 3 additions & 3 deletions imagepy/menus/Process/Hydrology/hydrology_plgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def run(self, ips, snap, img, para = None):

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

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

def run(self, ips, snap, img, para = None):
Expand Down
2 changes: 1 addition & 1 deletion imagepy/menus/Process/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
catlog = ['Math', 'Binary', 'Filters', '-', 'Threshold', 'Hydrology', 'Features', 'Segment', 'repair_plg', '-', 'calculator_plg']
catlog = ['Math', 'Binary', 'Filters', 'FFT', '-', 'Threshold', 'Hydrology', 'Features', 'Segment', 'repair_plg', '-', 'calculator_plg']
2 changes: 1 addition & 1 deletion imagepy/ui/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def merge(self, img, back, M, O, mode, shape, win, lookup):
if img.ndim == 2:
rstarr = np.zeros(shape, dtype=img.dtype)
my_transform(img, M, offset=O, output=rstarr, k=1, clip=False)
if rstarr.dtype == np.complex128: rstarr = np.abs(rstarr)
rstarr = lookup(rstarr)

if img.ndim == 3:
rstarr = np.zeros((win[3], win[2], 3), dtype=img.dtype)
for i in range(3):
Expand Down

0 comments on commit ed8a2fe

Please sign in to comment.