Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #68 from pr4deepr/master
Browse files Browse the repository at this point in the history
Add support for importing ellipse and freehand ROIs from ImageJ
  • Loading branch information
kushalkolar committed Oct 10, 2021
2 parents 3734d0c + e06940c commit 283d012
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/source/user_guides/viewer/modules/roi_manager.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Add ROI button Add Polygon ROI (Manual mode)
Show all Show all ROIs in the viewer
Live plot Live update of the curve plot with changes (Manual mode)
Plot Plot the curves (Manual mode)
Import from ImageJ Import ROIs from an ImageJ ROIs zip file (Manual mode)
Import from ImageJ Import ROIs from an ImageJ ROIs zip file (Manual mode). Freehand ROIs are downsampled by 5.
Switch to manual ... Switch to Manual mode. Clears CNMF(E) ROIs.

ROIs list Color-coded list of ROIs.
Expand Down
33 changes: 27 additions & 6 deletions mesmerize/viewer/modules/roi_manager_modules/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from matplotlib import cm as matplotlib_color_map
from tqdm import tqdm
import logging

from itertools import product as iter_product

if HAS_CAIMAN:
from caiman.utils.visualization import get_contours as caiman_get_contours
Expand Down Expand Up @@ -178,11 +178,32 @@ def import_from_imagej(self, path: str):
"""
ij_roi = read_imagej(path)
for k in ij_roi.keys():
xs = ij_roi[k]['x']
ys = ij_roi[k]['y']
ps = list(zip(xs, ys))

roi = ManualROI.from_positions(positions=ps,
if ij_roi[k]['type'] in ('oval', 'rectangle'):
width=ij_roi[k]['width']
height=ij_roi[k]['height']
left=ij_roi[k]['left']
top=ij_roi[k]['top']
if ij_roi[k]['type'] == 'oval':
x_bottom=left
y_bottom=top+height
ps=[x_bottom,y_bottom,width,height]
roi= ManualROI.from_ellipse(positions=ps,
curve_plot_item=self.get_plot_item(),
view_box=self.vi.viewer.getView())
else:
ps=list(iter_product((left,left+width),(top,top+height)))
ps[2],ps[3]=ps[3],ps[2] #swap coordinates so it draws coordinates in sequence
elif (ij_roi[k]['type']=='freehand'):
#freehand ROIs have large number of datapoints, so reducing it by a fifth
xs = ij_roi[k]['x'][::5]
ys = ij_roi[k]['y'][::5]
ps = list(zip(xs, ys))
else:
xs = ij_roi[k]['x']
ys = ij_roi[k]['y']
ps = list(zip(xs, ys))
if ij_roi[k]['type'] != 'oval':
roi = ManualROI.from_positions(positions=ps,
curve_plot_item=self.get_plot_item(),
view_box=self.vi.viewer.getView())
self.roi_list.append(roi)
Expand Down
10 changes: 10 additions & 0 deletions mesmerize/viewer/modules/roi_manager_modules/roi_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ def from_positions(cls, curve_plot_item: pg.PlotDataItem, view_box: pg.ViewBox,
roi_graphics_object = pg.PolyLineROI(positions=positions, closed=True, removable=True)
return cls(curve_plot_item=curve_plot_item, roi_graphics_object=roi_graphics_object, view_box=view_box)

@classmethod
def from_ellipse(cls, curve_plot_item: pg.PlotDataItem, view_box: pg.ViewBox, positions: list):
"""
Create an ellipse from a list of positions when importing ImageJ ROIs.
:param positions: [origin_bottom_x, origin_bottom_y, width, height]
"""

roi_graphics_object = pg.EllipseROI(pos=[positions[0], positions[1]], size=[int(positions[2]), int(positions[3])], removable=True)
return cls(curve_plot_item=curve_plot_item, roi_graphics_object=roi_graphics_object, view_box=view_box)

class ScatterROI(BaseROI):
"""A class for unmoveable ROIs drawn using scatter points"""
Expand Down

0 comments on commit 283d012

Please sign in to comment.