How to re-segment (finding half-point) ROI?

I made a ROI associated with an ultrasound image. For post-process, I want to segment the ROI into halves based on the distance between left and right corner of the ROI.
I managed to add a straight line and obtain the midpoint of those two points.
However, I am not able to separate the previously obtained ROI into left and right using the point.
What I am trying to do is get the cross-sectional area of those two individual ROIs.

I would like to know if there is a possible way to do so. Alternatively, I can choose to not use ROI function and measure the CSA and record it. But I wanted to see if I can keep the ROI for future use and use it for left and right measures.

Hello jeon -

I’m not aware of anything built in to Fiji / ImageJ that does what
you want, but it should be straightforward to do it programmatically
using something like java or jython (python).

Could you post the code you used to process the images you
posted? That would show us what you’ve already done and what
tools you are comfortable using.

(What I imagine is that you have a PolygonRoi and your midpoint
line. You would then iterate through the points defining your
polygon, e.g., PolygonRoi.getPolygon.xPoints, .yPoints
and build your left and right Rois using those and your midpoint

Thanks, mm

Hello Mountain_man,

I did not use any code to process the images. All points were manually selected with polygon feature in ImageJ software .
Also, I am not familiar with java or python at this point.

Will there be a possible way for the program to automatically recognize and create ROI just like I created with python or java?

Thank you,

Hello Hyunjae -

There are two issues here:

The first is how to programmatically locate the structure you
highlighted in the image you posted. The second is how to
split the ROI for that structure into left and right halves.

The first falls under the topic of segmentation, and, in general,
can be rather difficult, and the best approach is likely to be
specific to your particular use case. Fiji / ImageJ does have
various segmentation tools. You might start by trying to
segment your image semi-manually (that is, without drawing the
structure’s ROI by hand) using the Fiji / ImageJ gui application.
You might look at preprocessing the image using things like
blurring or edge detection or thresholding before running one
of ImageJ’s segmentation algorithms. If you find a semi-manual
method that works reliably, it should be fairly straightforward
to automate it.

Hopefully some of the image processing / segmentation experts
on this forum will have some suggestions for you. (I don’t.)

The second issue – splitting the ROI in half – can easily be
done by piecing together a couple of built-in ImageJ tools
using jython (python) (or java or another scripting language
like ImageJ Macro). (I don’t know of a way to do it with a
single built-in function.)

Here is a jython script that runs on my .tif version of your image:

from ij import IJ
from ij.gui import Roi, ShapeRoi
from ij.plugin.frame import RoiManager

# open image and get its overlay ('knee_overlay.tif')
imp = IJ.getImage()
ovr = imp.getOverlay()
# hide Overlay to avoid distraction
imp.setHideOverlay (True)

# convert overlay to Roi
rm = RoiManager.getRoiManager()
rm.setOverlay (ovr)
roi = rm.getRoi (0)

# the above is just the setup
# now you have your roi (somehow) (and your image)

# get Roi's bounding box
x = roi.getBounds().getX()
y = roi.getBounds().getY()
w = roi.getBounds().getWidth()
h = roi.getBounds().getHeight()

# use ShapeRoi's to intersect with left and right halves of bounding box
sa = ShapeRoi (roi)
sl = sa.clone().and (ShapeRoi (Roi (x, y, w / 2, h)))
sr = sa.clone().and (ShapeRoi (Roi (x + w / 2, y, w / 2, h)))

# add to ROI Manager for conveniene
rm.addRoi (sl)
rm.addRoi (sr)

Here is my .tif version of your image:

knee_overlay.tif (7.1 MB)

In it I added a coarser overlay as a surrogate for your
ROI so that I could retrieve the ROI from the image. For
my script to run you will have to download it and put it
someplace that ImageJ can find it (or edit the path to
the image in the script).

And here is a .tif version of the image with the two half
ROIs included as an overlay.

knee_split_overlay.tif (7.1 MB)

(I am using .tif’s here because they can include overlays,
rather than just “flattened” images with the ROIs drawn
directly on the images.)

And for forum-viewing convenience, here are the two images
as flattened .jpg’s:



Thanks, mm

Hi Mountain_man,

I deeply appreciate your insight into this process. I will go ahead and learn more into those additional features and also the jython code you provided.

Thanks, Hyunjae