Crop a ROI keeping the annotations

Hello!

I have an image with a dimension of 5000x5000 and with cell annotations. In QuPath, I would like to crop it in ROIs without loose the annotations and so save all the ROIs separately with each annotations. Is that possible?

Sorry maybe it is a silly question but I cannot find useful information online.

Thank you in advance.
Valeria

Could you clarify what you want? ROIs can be saved as text files, Masks, RGB pictures of the original image with an overlay, etc.
Most of those options are described in the documents, but might need to be modified for a particular use case.

Hello!

Thank you for your answer and sorry if I was not clear!
I would like to save the ROI in png and the annotation in Geojson. The thing is I know how to save the ROI after the selection of the rectangle tool; and I know how to save the annotation inside the rectangle creating the hierarchy. But the problem is that the annotation coordinates refers to the big image and not just the ROI, thus if i just cut the ROI, visualize it in QuPath and then import the annotation, they will not match anymore.

Thank you for your help and please let me know if there is something unclear.
Best,
Valeria

Ok, I think I am starting to understand. The confusion is that ROI has a very specific meaning in QuPath and ImageJ - essentially the coordinates that define an annotation or detection. Thus ROIManager in FIJI. In QuPath it can be found using .getROI(). Annotations and detections are the two kind of QuPath objects, there are no ROI objects:
https://qupath.readthedocs.io/en/latest/docs/concepts/object_hierarchy.html

I am guessing now that you meant a general region of interest, not the region of interest as a code object.

But yes, if you change the image, the coordinates will not match - you would need to alter the XY coordinates based on the cropped image - usually those are taken from the name of the cropped image file in some way.

“Image 1” has object A
“Image 1 Tile 4 [1923, 8245]” would then put object A at X-1923, Y-8245 since the upper left coordinate has moved. Without knowing at what location the image was cropped, it would be impossible to put the annotations back in after the fact - the annotations do not belong in the cropped image.

I do not know of any way to maintain the QuPath object locations automatically when cropping, but maybe @petebankhead has something.

Edit - come to think of it, maybe the “Send region to ImageJ” option would work - kind of? As long as the annotation being sent IS the bounding box. Using a mask image of the same region might be an even cleaner method, depending on the downstream use. And is already supported by the software.

1 Like

Hi @ValeAri, can you explain in more detail why you want to do this, and what would be the next step for you if you can achieve this export?

Hello and thank you for your answer!
Yes I tried to send the region to ImageJ but I am not finding a proper solution for my problem. I am still working on it anyway!

Best,
Valeria

1 Like

Hello Dr Bankhead,

Thank you for answering me and for your help!
The pathologist in the team where I work is using QuPath for making annotations and she is using quite huge images (~10000x10000px) in order to have a clear idea of the cells in the tissue sample. After that, I will extract the Geojson file with the annotations and with few manipulation use the data to train a DL model. And for this part it would be better for me to use images with the size of 1000x1000px (this images will be added to a previous traing set with this images’ dimension); thus I was thinking to leave the pathologist annotate the big image in order to facilitate her work and for my part, to crop it in tiles maintaining the annotation.

Probably I am just complicating everything and the easier solution is to cut the tiles before the annotation, but I was thinking that in Qupath there was a code or tool that implement it.

Thank you in advance.
Valeria

Thanks Valeria, it sounds like it is better for the pathologist to annotate on the full image.

Would it be an option for you to just export the labelled images you need for your DL model directly from QuPath, rather than using GeoJSON? There are lots of ways to export Exporting annotations — QuPath 0.2.3 documentation

Otherwise, I expect you’ll need to read in the GeoJSON and create labelled images somewhere else anyway (Python…?). I think it makes sense to do that work in QuPath.

However, if you prefer to interpret the GeoJSON elsewhere then the only transform you might need to apply is to translate all the coordinates according to the origin (top left corner) of the boundary box of the 1000x1000 pixel image relative to the original slide. You could encode that information in the filename of the GeoJSON / image tile when exporting from QuPath.

2 Likes

Thank you for you answer! :smile:
At the end, the simple labelled image is enough and fewer modification will be required.
I knew that I was just complicated my life with the Geojson files! :roll_eyes:

Have a nice day!
Valeria

2 Likes