Skip to content

Commit

Permalink
stackreg
Browse files Browse the repository at this point in the history
  • Loading branch information
yxdragon committed Feb 28, 2019
1 parent 5f8484f commit fb0f9a1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
- openpyxl
- pandas
- pydicom
- pystackreg
- pypubsub
- read-roi
- scikit-image
Expand Down
Empty file.
57 changes: 57 additions & 0 deletions imagepy/menus/Plugins/StackReg/stackreg_plgs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from imagepy.core.engine import Filter, Simple
from imagepy import IPy
from pystackreg import StackReg
import numpy as np
import pandas as pd
from skimage import transform as tf
from imagepy.core.manager import TableManager

class Register(Simple):
title = 'Stack Register'
note = ['8-bit', '16-bit', 'int', 'float', 'stack']

para = {'trans':'RIGID_BODY', 'ref':'previous', 'tab':False, 'new':'Inplace'}
view = [(list, 'trans', ['TRANSLATION', 'RIGID_BODY', 'SCALED_ROTATION', 'AFFINE', 'BILINEAR'], str, 'transform', ''),
(list, 'ref', ['previous', 'first', 'mean'], str, 'image', ''),
(list, 'new', ['Inplace', 'New', 'None'], str, 'reference', ''),
(bool, 'tab', 'show table')]

def run(self, ips, imgs, para = None):
news = np.array(imgs)
sr = StackReg(eval('StackReg.%s'%para['trans']))
sr.register_stack(news, reference=para['ref'])
mats = sr._tmats.reshape((sr._tmats.shape[0],-1))
if para['tab']: IPy.show_table(pd.DataFrame(
mats, columns=['A%d'%(i+1) for i in range(mats.shape[1])]), title='%s-Tmats'%ips.title)
if para['new'] == 'None': return
for i in range(sr._tmats.shape[0]):
tform = tf.ProjectiveTransform(matrix=sr._tmats[i])
if para['new'] == 'Inplace':
imgs[i] = tf.warp(imgs[i], tform)*imgs[i].max()
if para['new'] == 'New':
news[i] = tf.warp(imgs[i], tform)*imgs[i].max()
if para['new'] == 'New': IPy.show_img(news, '%s-reg'%ips.title)

class Transform(Simple):
title = 'Register By Mats'
note = ['all']

para = {'mat':None, 'new':True}
view = [('tab', 'mat', 'transfrom', 'matrix'),
(bool, 'new', 'new image')]

def run(self, ips, imgs, para = None):
mats = TableManager.get(para['mat']).data.values
if len(imgs) != len(mats):
IPy.alert('image stack must has the same length as transfrom mats!')
return
newimgs = []
for i in range(len(mats)):
tform = tf.ProjectiveTransform(matrix=mats[i].reshape((3,3)))
img = tf.warp(imgs[i], tform)
img -= imgs[i].min(); img *= imgs[i].max() - imgs[i].min()
if para['new']: newimgs.append(img)
else: imgs[i] = img
if para['new']: IPy.show_img(newimgs, '%s-trans'%ips.title)

plgs = [Register, Transform]
2 changes: 1 addition & 1 deletion imagepy/menus/Plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
catlog = ['New', 'Macros', 'Manager', '-', 'Install', 'Contribute', 'update_plg', '-', 'screencap_plg', 'Games']
catlog = ['New', 'Macros', 'Manager', '-', 'Install', 'Contribute', 'update_plg', '-', 'StackReg', 'Games', 'screencap_plg']
1 change: 0 additions & 1 deletion imagepy/menus/Process/Filters/classic_plgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ class Variance(Filter):

#process
def run(self, ips, snap, img, para = None):
print(snap.dtype, img.dtype)
nimg.uniform_filter(snap**2, para['size'], output=img)
img -= nimg.uniform_filter(snap, para['size'])**2

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_data_files():
'read_roi',
'numpy-stl',
'pydicom',
'pystackreg',
'pandas',
'xlrd',
'xlwt',
Expand Down

0 comments on commit fb0f9a1

Please sign in to comment.