-
Notifications
You must be signed in to change notification settings - Fork 272
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
Is it possible to import python-opencv contours? #81
Comments
This is certainly possible, although will involve writing some Python and/or Groovy code. The basic process is:
There is some information relevant to the last 3 steps at #61 For the first step, there are a few different options:
Of these, I would choose the last option. There may be some merit in the others, but I expect they would be more complicated to set up. There are lots of tricks and shortcuts in Groovy that may help with the parsing, e.g. in order to extract floating point coordinates (such as those required to construct the String inputString = "1.0, 2.0, 3.0, 4.0, 50.0"
float[] x = inputString.tokenize(',') as float[]
print x Finally, I should mention that the coordinates should be in pixel units corresponding to the highest-resolution plane in your SVS file. |
Excellent, I'll have a go at this. Thanks for the quick answer! |
If you get this working, I would love to see how! |
Does the script have to be run from the QuPath GUI? I'm trying something similar, do let me know if you got this working @ElEd2 |
Unfortunately I've had to park my image segmentation project for now, so might be a couple of months before I get back to this. |
Hi, Sorry, took me a while to get back to this. I've written some code to write python opencv contours to file
and groovy code to read them in:
Cheers, |
@ElEd2 Thank you for the scripts! I'll be using them once I figure out how to use the groovy code. Quick question: In my case, I have contours for the entire slide area. This means millions of vertices if I output everything naively. Do you experience any performance issues with loading or zooming in your case? |
I can't speak for @ElEd2 (thanks from me too for the scripts!), but performance should be ok. One important thing is that you should definitely use With this many objects involved, you also probably don't want to add your objects to the hierarchy one-by-one within the loop, since this will trigger a lot of costly checks and events. Calling def pathObjects = []
for (i = 0; i <num_rois; i++) {
// The rest of the stuff, as above
pathObjects << new PathDetectionObject(roi)
}
addObjects(pathObjects) If this still doesn't perform well enough, and you don't mind deleting anything that might already exist on the hierarchy, using the following instead of clearAllObjects()
getCurrentHierarchy().getRootObject().addPathObjects(pathObjects)
fireHierarchyUpdate() Anyhow, the reason I think that it should work one way or another is that you can generate similar numbers of vertices running the cell detection in QuPath itself. In that case, various tricks are used to help, e.g.
You could do the polygon simplification on the OpenCV side, perhaps with Despite all that, I haven't tried doing this exact conversion before and my guess is that you might have a problem with having really really huge text files. If that's the case then it could be the bottleneck... but that can be solved too if necessary. |
I've now written a bit about OpenCV contours & QuPath in a blog post. |
Hi,
I'm interested in using QuPath to explore the results of an image segmentation algorithm (for large .svs files) I've written in python+opencv. Would this work? What would be the best way to load the contours?
Cheers,
Ed
The text was updated successfully, but these errors were encountered: