2D metrics tools => ROI

80 views
Skip to first unread message

françois xavier Arnaud

unread,
Jun 14, 2024, 4:50:12 AM6/14/24
to Pylinac
Hey all,
I'm struggling to use 2D metrics for an image using pylinac.metrics.image DiskRegion.
I want to generate a simple spherical ROI at the center of my image using this tool and get metrics from it.

In the Documentation it says that "The SizedDiskRegion metric is the same as the SizedDiskLocator, but instead of returning the location, it returns a scikit-image regionprops object that is the region of the disk. This allows one to then calculate things like the weighted centroid, area, etc.

It also supports the same class methods as the SizedDiskLocator metric."

Does it mean that I have to give (for example) a radius_tolerance (mandatory) for a simple ROI? 

Do you have a simple example of it ? it seems that maybe I'm misunderstanding it.


Thanks.

François

Safir

unread,
Jun 17, 2024, 9:49:37 AM6/17/24
to Pylinac
Hello François,

If you want to generate a simple spherical ROI at the center of your image, I believe that something along these lines should work, although there might be a better way to do it. It creates a circular ROI at the center of the image, then plots it and gives the median pixel value of the ROI:


from pylinac.core.roi import DiskROI
import pydicom
import matplotlib.pyplot as plt
from pylinac.core.geometry import Point

img=r"yourpath.dcm"
ds = pydicom.dcmread(img)
roi = DiskROI(array=ds.pixel_array, angle=0, roi_radius=14, dist_from_center=0,phantom_center=Point(ds.Rows/2, ds.Columns/2))


fig, ax = plt.subplots()
ax.imshow(ds.pixel_array, cmap='bone')
roi.plot2axes(ax)
plt.show()


print(roi.pixel_value)

This doesn't automatically find the ROI through image analysis, so maybe it is not exactly what you wanted.

Regards,

Safir

James Kerns

unread,
Jun 20, 2024, 12:16:22 PM6/20/24
to Pylinac
If you want to simply sample an ROI with an exact, known location you can follow what Safir suggested. Both disks and rectangles are supported. These ROIs can provide the mean pixel value,  std, etc. 

If the disk is a feature of the image and the exact location is unknown, that's what the 2D metrics toolbox is for. This will find a BB, hole, etc within the image. 

I am working on a cookbook section for pylinac and will include a few examples of each. 

françois xavier Arnaud

unread,
Jun 24, 2024, 5:06:25 PM6/24/24
to Pylinac
ok thanks for the answers. i misunderstood, I thought that I could use  pylinac.metrics.image DiskRegion just to get mean values in a ROI.
thanks for the help

Reply all
Reply to author
Forward
0 new messages