Cropping and exporting Image

Hi there,

I hope there is a solution to this, albeit I realize this is a strange approach.

I would like to export co-ordinates from annotations within a rectangle, with the co-ordinates being relative to the said rectangle not the entire slide.

Possible solution: I draw a large rectangle within my slide and crop the image so that only that rectangle remains. The first point of the rectangle should become the new (0,0) co-ordinate. Therefore I can draw new annotations on the cropped image and export those co-ordinates.

I can successfully export co-ordinates but I don’t know how to crop a digital slide, or if a better workaround can be achieved.

Original Image:

After sending rectangle to ImageJ and opening in Qupath 0.2.0 -m2

Many thanks,

I would recommend being careful about what your coordinates mean, as I don’t know the extent of your background. Some functions in QuPath will return the pixel based coordinates, and others will return distance based coordinates. Depending on what you want, you can create a rectangle and export it to ImageJ (Extensions menu), save it, and the reopen it in QuPath. Make sure your pixels mean what you think that they mean (Image->Properties in ImageJ) if you take this route.


Thanks for your input! I have previously been using pixel based coordinates, but I believe these would become useless once I export and downscale with the ImageJ plugin. I don’t see why I couldn’t use the distance based co-ordinates with the approach you suggested, do you know how to export these instead of the pixel based ones?

As long as you keep track of what a pixel means, you should be able to perform the conversion. 4x downsample will have 4 times the size in microns per pixel. Be careful whether you are looking at microns per pixel or pixels per micron. What you export and how also depend on your image and what metadata QuPath is able to read, so it is hard to give generic advice. You would need to share your particular example, or at least give more information about what version you are using and what metadata QuPath is already reading.


I’ve edited my original post to show the image properties of 1. My original image and 2. The exported rectangle (downscale factor 20).

I’m using the export coordinates script from:

If I was to now to draw and export coordinates from the Imagej export using the above script and get the following coordinates:

5065.679279279279, 3215.5121621621624
6656.426126126126, 3215.5121621621624
6656.426126126126, 4528.264414414414
5065.679279279279, 4528.264414414414

How would I do the conversion so that these points accurately scale to the original image?
(Apologies, I’m still coming to terms with how Qupath handles the metadata)

@Amygdala1 can you say more about what precisely you want to do and why? i.e. how this relates to ImageJ.

I ask because there could be multiple ways to handle it. The easiest, if appropriate, is to let QuPath do the work for you. When you send a region to ImageJ, this can include any annotations made in QuPath already (as the main Roi or as Rois on an overlays). These will be preserved if you save an ImageJ TIFF.

Similarly, if you create a ROI in ImageJ - within an image that QuPath extracted itself - then you can send that back to QuPath, and all the translation/rescaling will be done for you to position that ROI as an annotation (or detection) in the right place in the whole slide image.

There is some more information at

In practice, this works by setting the ImageJ properties (specifically the pixel size and origin with the Calibration object of the ImagePlus) so that QuPath can relate these back to the original slide. If these properties are lost then the conversion won’t work.

1 Like

Extra bit… I see you exported while downsampling by a factor of 10.

To get the region back to the whole slide image, you’ll need to open your TIFF within ImageJ through QuPath (easiest is to send a region/snapshot to ImageJ to open the ImageJ window), and the whole slide image itself within QuPath. Then you can use the ‘Send ROI/Send Overlay’ commands from ImageJ to send the regions to QuPath.

Yeah, that compared to the listed downsample of 20 has me a little bit worried.

Sorry it was a downsample of 10 - my bad.

1 Like

Thanks for responding Pete.

Basically I’m trying to develop a method of transfer coordinates between Qupath and a specialized piece of equipment. For this I need to a transformation to ensure the Qupath and the machine are compatible. (This script is written, and all I need to do is get the accurate co-ordinates between the two)

The task I need to accomplish is to set a reference point (i.e. an annotation within a pre-defined rectangle) and export the coordinates of that annotation. To do this, I planned on scanning a digital slide with a scale (the slide is blank with no histology tissue on it), draw a rectangle for the size I needed, from there I exported it to ImageJ as Research_Associate suggested. Now, if I wish to draw the annotations I need, but as I understand the annotations wouldn’t be representative as the image has been downscaled.

In short, I would like to draw a rectangle, make annotations within that rectangle and then export the co-ordinates so they are relative to the rectangle not the whole image itself… sorry if this is all so confusing :sweat_smile::sweat_smile::sweat_smile:

I think I get it… but I’m not sure :slight_smile:

I think you then need to export the original coordinates, and just subtract the ‘origin’ (top left) or your rectangle? And possibly multiply/divide by a scaling factor…?

For all ROIs in QuPath you can call roi.getBoundsX() and roi.getBoundsY() to get the top left in ‘pixel units’ (there are getBoundsWidth() and getBoundsHeight() methods as well). Don’t know if that’s what you need but it’s something :slight_smile:

There’s also a bit more info about the concepts & scripting at

1 Like