How can I sort images in the image list in QuPath?

Hi, another probably elementary question from my side; in my project I have added new images now and then, but I want these images to follow a certain order (I have given them numbers) so that it’s easy for me to find them when I am working in QuPath. Is there a way to sort the images in the project / in the image list?

Hi @elisyn,

What do you mean by ‘you have given them numbers’?

I’m thinking that you could add the numbers as metadata (right click > Add metadata > e.g. {new key: Id, new value: 1}) then hit right click > Sort by… > Id on any entry in your project.
Also, you could import each image directly in the right order, as each new image is added at the end of the list.

1 Like

Thanks @melvingelbard , yes, I regret I did not wait until I had all the sections ready and scanned, then I would have had them in the right order, now I struggle to keep an overview.
What if I delete the project, and create a new one where I import the images in the right order? Will I risk to lose something (I have many annotations on 120 images, each image has taken hours or even days)

It might be easier and safer to automate the process in the current project?
For instance, it would be possible to parse the filename (e.g. a date) and assign a number to the project entry (in the entry’s metadata) based on it:
filename 02/05/2020.png > 1
filename 08/05/2020.png > 2
filename 01/06/2020.png > 3
...

1 Like

@elisyn can you give examples of the image names you’re using, and how you’d like them to be sorted?

As @melvingelbard suggests, there isn’t currently a way to sort images in a project after they have been added. But you can add metadata values and sort by those – and you can potentially do this very quickly in a script. But to write the script, it’s necessary to be able to figure out the correct order from the name somehow.

1 Like

Hi, thanks both!

The image names I use are just the slide numbers, 5005, 5006, 5010, 5012….
It would be easier to navigate if they were arranged in order.

If I use metadata to order them in the image list, then I could enter 1 as new key, and the slide number as new value, and then I can have the images sorted the way I want in the list ? When I right click on the project name in the image list though, there is an option to sort by none or to sort by URL, but not an option to sort by metadata?

You could use the following script for each entry in your project:

def imageData = getCurrentImageData()
def name = GeneralTools.getNameWithoutExtension(imageData.getServer().getMetadata().getName())
getProjectEntry().putMetadataValue("Id", name)

Then right click on any entry in the project, Sort by… > Id (it should now appear!).
Try on one image first to see if this suits what you want to do!

1 Like