Page 1 of 1
Read in MATLAB ROIs from CZI file
Posted:
Tue Aug 28, 2018 11:25 am
by espezi
Dear community,
we are new to bio-format so the answer to this question may be trivial, but I could not find to date an example of how to import in MATLAB ROIs from a CZI file.
We have several CZI files where ROIs were defined using the ZEN application. The ROIs are visible in ZEN and can also successfully imported and displayed in OMERO. With MATLAB we can read the images fine but we cannot find a way to import the ROIs as a set of points in the coordinate system of the image. Does anyone have an example script showing how this can be done in MATLAB?
We went as far as using the r.getMetadataStore().getROICount command (reading the bfopen.m code) but cannot get the points coordinates.
Any help would be very much appreciated.
Kind regards,
Emiliano
Re: Read in MATLAB ROIs from CZI file
Posted:
Wed Aug 29, 2018 9:45 am
by dgault
Hi Emiliano,
There is a utility function which can parse through and print out ROI's (
https://github.com/openmicroscopy/biofo ... tROIs.java). Although it doesn't return the coordinates you can use the same logic as it does to print them.
First it retrieves the ROICount as you have done and loops through all the ROI's:
https://github.com/openmicroscopy/biofo ... s.java#L56Next it uses getShapeCount to return the number of shapes in a particular ROI:
https://github.com/openmicroscopy/biofo ... s.java#L88You can then get a Union of all these shapes and loop through each shape:
https://github.com/openmicroscopy/biofo ... s.java#L96Lastly you will have to check what type each shape (
https://github.com/openmicroscopy/biofo ... .java#L107) and access the relevant points (for example a Point shape has X, Y and text
https://github.com/openmicroscopy/biofo ... .java#L128 while an Ellipse will also have RadiusX and RadiusY
https://github.com/openmicroscopy/biofo ... .java#L109)
Hopefully you can reuse a lot of this logic in order to access the ROI coordinates needed
David Gault
Re: Read in MATLAB ROIs from CZI file
Posted:
Wed Aug 29, 2018 11:03 am
by espezi
Thanks very much for your reply David.
I understand the logic and could try to find a way of calling the java code you pointed out from MATLAB, but I wonder if there is an example of code written in the MATLAB language.
Kind regards,
Emiliano
Re: Read in MATLAB ROIs from CZI file
Posted:
Thu Aug 30, 2018 3:07 pm
by dgault
Im afraid we don't have a MATLAB example of this specific ROI access, however it would look something very similar to the below code:
- Code: Select all
omexml = r.getMetadataStore();
roiCount = omexml.getROICount();
for roi = 1:roiCount
int shapeCount = omexml.getShapeCount(roi);
allShapes = omexml.getRoot().getROI(roi).getUnion();
for shape = 1:shapeCount
shapeObject = allShapes.getShape(shape);
shapeType = omexml.getShapeType(roi, shape);
if strcmp(shapeType,'Ellipse')
text = omexml.getEllipseText(roi, shape);
pointX = omexml.getEllipseX(roi, shape);
pointY = omexml.getEllipseY(roi, shape);
radiusX = omexml.getEllipseRadiusX(roi, shape);
radiusY = omexml.getEllipseRadiusY(roi, shape);
else if strcmp(shapeType,'Line')
text = omexml.getLineText(roi, shape);
pointX1 = omexml.getLineX1(roi, shape);
pointX2 = omexml.getLineX2(roi, shape);
pointY1 = omexml.getLineY1(roi, shape);
pointY2= omexml.getLineY2(roi, shape);
else if strcmp(shapeType,'Point')
text = omexml.getPointText(roi, shape);
pointX = omexml.getPointX(roi, shape);
pointY = omexml.getPointY(roi, shape);
else if strcmp(shapeType,'Polyline')
text = omexml.getPolylineText(roi, shape);
points = omexml.getPolylinePoints(roi, shape);
else if strcmp(shapeType,'Polygon')
text = omexml.getPolygonText(roi, shape);
points = omexml.getPolygonPoints(roi, shape);
else if strcmp(shapeType,'Rectangle')
text = omexml.getRectangleText(roi, shape);
pointX = omexml.getRectangleX(roi, shape);
pointY = omexml.getRectangleY(roi, shape);
width = omexml.getRectangleWidth(roi, shape);
height = omexml.getRectangleHeight(roi, shape);
else if strcmp(shapeType,'Label')
text = omexml.getLabelText(roi, shape);
pointX = omexml.getLabelX(roi, shape);
pointY = omexml.getLabelY(roi, shape);
else if strcmp(shapeType,'Mask')
text = omexml.getMaskText(roi, shape);
pointX = omexml.getMaskX(roi, shape);
pointY = omexml.getMaskY(roi, shape);
width = omexml.getMaskWidth(roi, shape);
height = omexml.getMaskHeight(roi, shape);
end
end
end
Re: Read in MATLAB ROIs from CZI file
Posted:
Fri Aug 31, 2018 10:42 am
by espezi
Thanks this is very similar to what I wrote since the last post. I was able to get the points from the Polygon and the shape looks indeed correct when compared to what I see in the ZEN app. But now I will compare the points from your code and mine.
I am interested in overlaying (and eventually masking) the image with the ROI.
How can the spatial coordinates of the image pixels can be extracted (so that I can plot them together with the ROI an ensure the spatial location is correct)?
This post "https://docs.openmicroscopy.org/bio-formats/5.9.0/developers/matlab-dev.html" explains how to get the physical voxel and stack sizes of the data. But I could not find a mention of the origin of the coordinate system.
Many thanks!
Emiliano
Re: Read in MATLAB ROIs from CZI file
Posted:
Tue Sep 04, 2018 7:25 am
by espezi
Hi there,
I understand that there is no actual frame or reference but the coordinate points are relative to the upper left corner of the image. I have now the code that reads and masks the image with the ROIs. We shall share it when it's polished and full tested. Many thanks.
Best regards,
Emiliano