How to cut square in size 160x160 from a bigger image in Qupath


I am making annotations of cells in qupath to create a training set suitable for running a model in stardist. I want to draw a square 160x160 in a image that is bigger for example 230x230 and then I want to make annotations inside a square 160x160.
I have two problems

  1. I do not know how I can draw a square with the size of 160x160
  2. when I start the annotations process I see that it’s impossible to annotate cells inside this square.

How I can solve these problems?

Hi @Mariya_Timotey_Mitev

To be able to draw inside annotations, you need to lock them first.

Right click on the annotation (your square) and select Annotation > Lock.
Now you can draw inside.

To make a rectangle the size you want, you need a script as far as I know.

import qupath.lib.objects.PathObjects
import qupath.lib.roi.ROIs
import qupath.lib.regions.ImagePlane

int z = 0
int t = 0
def plane = ImagePlane.getPlane(z, t)
def roi = ROIs.createRectangleROI(0, 0, 160, 160, plane)
def annotation = PathObjects.createAnnotationObject(roi)

You can then move your annotation to where you want. You can also use CTRL+D to make a copy of your annotation if you need more than one in the image.

I think that there is also a command to transfer annotations from one image to the other but I am currently on my phone so I cannot check :sweat_smile:


There’s also Objects → Annotations… → Specify annotations and Classify → Training regions → Create training regions.

Admittedly they do quite similar things… and perhaps should become a single command some day.

This should work fine if you export individual tiles at the full resolution. If you want to export tiles of a fixed size at any other resolution, or multiple (perhaps-overlapping) tiles within an annotation, you’re generally better to try something from