Skip to content

Fix ROI conversion from instance segmentation mask#42

Merged
petebankhead merged 2 commits into
qupath:mainfrom
ajay1685:main
Nov 11, 2025
Merged

Fix ROI conversion from instance segmentation mask#42
petebankhead merged 2 commits into
qupath:mainfrom
ajay1685:main

Conversation

@ajay1685
Copy link
Copy Markdown
Contributor

@ajay1685 ajay1685 commented Nov 6, 2025

This commit fixes two issues:

  1. Corrects the ROI orientation for the instance segmentation masks.
  2. Corrects the scaling of ROI where Mask size is normalized to full Image (YOLOs) vs bounding box (Mask-RCNN) with different instance segmentation models.

I created an issue: #41

This commit fixes two issues:
1. Corrects the ROI orientation for the instance segmentation masks.
2. Handles the case where Mask is size of full Image vs a fixed size masked returned by Mask-RCNN instance segmentation models.
@petebankhead
Copy link
Copy Markdown
Member

Thanks, can you provide any specific examples of models and code that shows that this works?

@ajay1685
Copy link
Copy Markdown
Contributor Author

ajay1685 commented Nov 6, 2025

Sure, here is an example of Yolo11n-seg using pytorch

image

And, example of mask_rcnn_resnet18_v1b_coco using mxnet

image

I am running the current snapshot for QuPath and QuPath-extension-djl with the fix implemented.

Here is the script:

import qupath.ext.djl.*
boolean allowDownsamples = false
var artifacts = DjlZoo.listInstanceSegmentationModels();
var artifact = artifacts[0].getDefaultArtifact()
println "Model: ${artifact}"

var criteria = DjlZoo.loadModel(artifact, allowDownsamples)

var imageData = getCurrentImageData()
var detected = DjlZoo.detect(criteria, imageData)
println "Detected objects: ${detected.orElse([])}"

@ajay1685
Copy link
Copy Markdown
Contributor Author

ajay1685 commented Nov 6, 2025

This test shows the issue, if I run it without the proposed fix:

image

@ajay1685
Copy link
Copy Markdown
Contributor Author

ajay1685 commented Nov 7, 2025

While this seems to address the issue with the orientation and scaling, things to consider:

  1. Iterating over each element for raster might not be efficient if the mask dimensions are large (not an issue at the moment since both types of models return fixed size mask).
  2. Scaling of a fixed size mask (i.e. 14x14 for MASK-RCNN) to bounding box of a large object could benefit from interpolation before tracing.

Let me know your thoughts.

@petebankhead
Copy link
Copy Markdown
Member

Thanks, the changes look good to me!
I haven't looked at this extension for a while and notice the docs were outdated as well, so I've just made an update to them as well qupath/qupath-docs#168

@petebankhead petebankhead merged commit 77ab919 into qupath:main Nov 11, 2025
1 check passed
petebankhead added a commit to petebankhead/qupath that referenced this pull request Nov 11, 2025
@ajay1685
Copy link
Copy Markdown
Contributor Author

Thanks pete, I can also add an example of instance segmentation to the docs. I just finished setting up local repo and a python environment for the qupath-docs, please let me know.

ajay1685 added a commit to ajay1685/qupath-docs that referenced this pull request Feb 19, 2026
Instance segmentation models are available in QuPath. Refer to qupath/qupath-extension-djl#42
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

Successfully merging this pull request may close these issues.

2 participants