Skip to content

Commit

Permalink
Add is_rgb_merged method to check if image is RGB
Browse files Browse the repository at this point in the history
  • Loading branch information
elevans committed May 18, 2023
1 parent bcfa002 commit ccee1b3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/imagej/_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ def ImgView(self):
def ImgLabeling(self):
return "net.imglib2.roi.labeling.ImgLabeling"

@JavaClasses.java_import
def IntegerType(self):
return "net.imglib2.type.numeric.IntegerType"

@JavaClasses.java_import
def Named(self):
return "org.scijava.Named"
Expand Down
28 changes: 28 additions & 0 deletions src/imagej/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ def _python_metadata_to_imgplus_metadata(py_metadata: dict):
return sj.to_java(py_metadata['imagej'])


def is_rgb_merged(img: "jc.ImgPlus") -> bool:
"""
Check if the ImgPlus is RGB merged.
:param img: An input net.imagej.ImgPlus
:return: bool
"""
e = img.firstElement()
# check if signed
if e.getMinValue() < 0:
return False
# check if integer type
if not isinstance(e, jc.IntegerType):
return False
# check if bits per pixel is 8
if e.getBitsPerPixel() != 8:
return False
# check for channel dimension (returns -1 if missing)
ch_index = img.dimensionIndex(jc.Axes.CHANNEL)
if ch_index < 0:
return False
# check if channel dimension is size 3 (RGB)
if img.dimension(ch_index) != 3:
return False

return True


def create_xarray_metadata(img: "jc.ImgPlus") -> dict:
"""
Create the ImageJ xarray.DataArray metadata.
Expand Down

0 comments on commit ccee1b3

Please sign in to comment.