Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Coordinates Not Matching Actual Annotations in QuPath #9

Open
Lililily0918 opened this issue Nov 28, 2023 · 1 comment
Open

JSON Coordinates Not Matching Actual Annotations in QuPath #9

Lililily0918 opened this issue Nov 28, 2023 · 1 comment

Comments

@Lililily0918
Copy link

Hello QuPath Community,

I'm encountering an issue with the annotation coordinates in QuPath (0.4.3), when annotations are made at different zoom levels (which cannot be avoided), the json and subsequent mask do not match with the actual annotation.

Attached is an example image with annotations:
(the actual annotation should be those deeply stained cells next the green mask)
cgi-bin_mmwebwx-bin_webwxgetmsgimg_ MsgID=3717326350272038047 skey=@crypt_fe9c1f40_7f13aef0e19d76037a2e3d40f9763d96 mmweb_appid=wx_webfilehelper

I have tried it both in MacOS and windows system, and for different versions, though the problem can't be solved.

I've been performing annotations on histopathological images at various zoom levels. However, when I export these annotations to a JSON file, the coordinates in the JSON do not seem to match the actual positions where I made the annotations in the QuPath viewer.

The code I exported json from the image are:

import qupath.lib.objects.PathObject
import qupath.lib.objects.hierarchy.PathObjectHierarchy
import qupath.lib.regions.RegionRequest
import qupath.lib.roi.ROIs
import qupath.lib.roi.interfaces.ROI

import java.awt.Color
import java.awt.Graphics2D
import java.awt.Shape
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO

def viewer = qupath.lib.gui.QuPathGUI.getInstance().getViewer()
def server = viewer.getServer()
def hierarchy = viewer.getHierarchy()

if (!server || !hierarchy) {
print("Error: No image or hierarchy loaded.")
return
}

def scaleFactor = 0.2
def width = (server.getWidth() * scaleFactor) as int
def height = (server.getHeight() * scaleFactor) as int

def img = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY)
Graphics2D g2d = img.createGraphics()
g2d.setColor(Color.WHITE)
g2d.scale(scaleFactor, scaleFactor)

for (PathObject annotation : hierarchy.getAnnotationObjects()) {
ROI roi = annotation.getROI()
Shape shape = roi.getShape()
g2d.fill(shape)
}

g2d.dispose()
\

def originalFilename = server.getMetadata().getName()
def outputFilename = originalFilename.replaceAll('(?i)\\.[^.]+$', '.png')

//

def outputDirectory = new File('path')
def outputFile = new File(outputDirectory, outputFilename)
ImageIO.write(img, "PNG", outputFile)

print("Mask saved to " + outputFile.getAbsolutePath())
}

Expected Behavior:
I expect the coordinates in the JSON file to accurately reflect the positions of my annotations, regardless of the zoom level at which they were made.

Actual Behavior:
The exported JSON coordinates do not align with the actual annotated positions, especially noticeable when annotations are made at varying zoom levels.

Queries:

  1. Is this a known issue with coordinate handling at different zoom levels in QuPath?
  2. What are the recommended steps to ensure consistent and accurate coordinate mapping across different zoom levels?

I would appreciate any guidance or suggestions on how to resolve this issue. If additional information is needed, I am happy to provide it.

Thank you for your assistance.

Best regards,
Lily

@NicoKiaru
Copy link

Hello @Lililily0918,

Are you sure this is an issue related to this repository ? Quickly looking at your issue, I'd recommend:

1 - to post your issue on forum.image.sc with the QuPath tag
2 - it looks like you are issue very low level graphical Java (awt, Graphics2D). I'm pretty sure it's not the correct way to add overlays in QuPath. You'd rather have to use higher level function of the QuPath API - but you'll get better answers on forum.image.sc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants