View miss classified patches on original .svs file

Hello everyone,

I am working on classification task of normal vs tumour on some medical images which are in .svs format. I have drawn patches of size 512 x 512 from a particular medical slide image. I trained mt machine learning classifier. After training, I got some miss-classified patches. Now I need to view these patches on the original slide so that we can understand which area of that slide is being miss classified more. Or I need to watch miss classified zone or pixels in original image. How to do it with Qupath? .Please help me out here. I am very new to the Qupath.

1 Like

Hi @Nikhil-cyber-93 ,

We might need some more info to fully understand the problem. For instance, where did you train and classified your patches? Was it in QuPath or somewhere else (Python, …)? What is the output format of your classification? (e.g. segmentation → patch where each pixel belongs to a specific class, defined by a pixel value/color like 0, 1, 2…; classification → a class/number for each patch)…

Any more information would be helpful.

3 Likes

Dear Melvin,
We trained the model on some external system using python. We used Qupath to view normal or tumour .svs file. We drew patches of small size (512 x 512) and stored in some folders and then use their path to classify them whether given patch image is normal or tumour. Output format of our classification is simply a number. 0 means normal and 1 means tumour. After validation, we have some patches (i.e. their paths) which are missclassified. I need to view the part in original .svs file from where these patches are drawn .

Is it possible?

Yes it should be possible.
For instance, if you have an output file (e.g. a CSV file) with all the patch paths (where the original position of the patch is included in the name) and their corresponding classification (0 or 1), you could create a script that does something like this:

  1. Iterate through the rows of the CSV file.
  2. Create annotations with the patch positions included in the paths (or just find the already-existing ones if you still have them).
  3. Set the classification of these annotations according to what’s written in the CSV file (0/1)

So first step would be:

  1. Make sure the patch position is included in the path (if you used the TileExporter it should be fine)
  2. Create that CSV file where the first column is the patch path and the second is the classification (0/1)

Then depending on your settings, we can create a small script that would do the rest. This would make it easier to visualise the classifications on the original svs.

4 Likes

@melvingelbard
I forgot to mention that, We drew patches from .svs file using OpenSlide library. We didn’t use Qupath exporter to draw patches. Does above solution given by you still applicable to my case??

@Nikhil-cyber-93 somehow you’ll need to have the coordinates of the patches you want to visualize. QuPath defines these uses pixel units. So a QuPath script to add a single 500x500 pixel rectangle to an image with its top left corner at (100,200) would be

def roi = ROIs.createRectangleROI(100, 200, 500, 500, ImagePlane.getDefaultPlane())
def classification = getPathClass("Tumor")
def pathObject = PathObjects.createAnnotationObject(roi, classification, null)
addObject(pathObject)

If you have large numbers you want to visualize at once, there are ways to optimize this, e.g. use createTileObject instead of createAnnotationObject, and add your objects all at once using addObjects rather than addObject. These changes could result in a huge improvement in performance if you want to visualize thousands of patches – but not if you just have a small number.

My guess is that the easiest way to get your coordinates would be to encode them in the filename of your patches.

3 Likes

Dear @petebankhead,

I created a new project, added a .svs file and clicked on create script. Then I ran the following code given by you( with and without saving).

setImageType('FLUORESCENCE');
import static qupath.lib.gui.scripting.QPEx.*
import qupath.lib.roi.ROIs
import qupath.lib.roi.RoiTools
import qupath.lib.objects.PathObjects
import qupath.lib.regions.ImagePlane

def roi = ROIs.createRectangleROI(10000, 10000, 5000, 5000, ImagePlane.getDefaultPlane())
def classification = getPathClass("Tumor")
def pathObject = PathObjects.createAnnotationObject(roi)
addObject(pathObject)
print(roi)

But problem is after running the script, I couldn’t see any changes in my viewer or the opened .svs image file. What could be the issue here

??

Edited the code to be code using image
If you Run the code it should work and the result should show up in the viewer. If you Run for Project, the result should NOT show up, as indicated by the red text when you Run for Project. Are you doing something different from those two options?
image

If you Run for Project and then Reload the data, it should show the rectangle. Possibly several on top of one another if you keep running it.

1 Like

@Nikhil-cyber-93 I’m unable to see how big your image is, so I don’t know if (10000,10000) as an origin is outside the visible part.

Check also the Annotations tab to see if something has been added, even if not visible.

1 Like