Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversion support for index images to ImgLib2 and legacy ImageJ ROIs #283

Merged
merged 13 commits into from
Jan 9, 2024
4 changes: 4 additions & 0 deletions src/imagej/_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def Img(self):
def ImgView(self):
return "net.imglib2.img.ImgView"

@JavaClasses.java_import
def DefaultWritablePolygon2D(self):
return "net.imglib2.roi.geom.real.DefaultWritablePolygon2D"

@JavaClasses.java_import
def ImgLabeling(self):
return "net.imglib2.roi.labeling.ImgLabeling"
Expand Down
5 changes: 4 additions & 1 deletion src/imagej/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,15 @@ def index_img_to_roi_manager(
print("The RoiManager is unavailable in headless mode.")


def _get_contours(ij: "jc.ImageJ", index_img: np.ndarray) -> List:
def _get_contours(
ij: "jc.ImageJ", index_img: np.ndarray
) -> List["jc.DefaultWritablePolygon2D"]:
elevans marked this conversation as resolved.
Show resolved Hide resolved
"""
Compute contours from an index image.

:param ij: The ImageJ2 gateway (see imagej.init)
:param index_img: An ImgLib2 or NumPy index image
elevans marked this conversation as resolved.
Show resolved Hide resolved
:return: A list of imglib2 2D poylgon ROIs
"""
contours = []
labels = np.unique(index_img)
Expand Down