Save detections image layer only

246 views
Skip to first unread message

Yupei Yang

unread,
Sep 5, 2018, 11:13:43 AM9/5/18
to QuPath users
Hi all,

As we know, QuPath could save original image and overlay image ( original layer + detection result layer).
Can we use a script that saves the detection result layer only, without original image layer?

Thanks in advance.

Yupei

Pete

unread,
Sep 5, 2018, 11:19:24 AM9/5/18
to QuPath users
If the purpose is to create a labelled image e.g. to use as training for deep learning, this may help: https://petebankhead.github.io/qupath/scripting/2018/03/14/script-export-labelled-images.html

Otherwise, can you say a bit more about what the output should be and what the purpose is?  It should definitely be possible with a script, but there would be choices to make about what background you want (e.g. white, black, transparent if a PNG) and if you want to use QuPath's built-in way of paining objects, or if you just want to access the shapes from QuPath and paint them in some other customized way.

Yupei Yang

unread,
Sep 5, 2018, 11:50:55 AM9/5/18
to QuPath users
Hi Pete,
Thanks for your help.
For example, the first image is the original one
The second is image overlay after processing Fast Cell Counts. (original + green layer).
My purpose is to export only the green layer with white background by using QuPath script.

137106.jpg
137106-overlay.jpg

Pete

unread,
Sep 5, 2018, 11:53:39 AM9/5/18
to QuPath users
If you're happy with exporting in the same way as you did for the screenshot, a trick I sometimes use is to enter the Brightness/Contrast and then play around with the sliders / display transforms so that the background looks all white.

If that's not enough, do you need this at full resolution, or a downsampled version of the image?  The second is definitely easier... QuPath doesn't have a built-in way to write a pyramidal whole slide image, it can only export 'small' regions (a typical JPEG or PNG, with width and height of a few thousand pixels each).  Therefore if you need the full resolution, you'd need to export one tile at a time... and potentially reassemble the image somewhere else.  This would be significantly more awkward.

Yupei Yang

unread,
Sep 14, 2018, 3:09:33 PM9/14/18
to QuPath users
Hi Pete,

Thanks for your suggestion.
For the first method to change the Brightness/Contract value, is that possible to have a script to automatically run it and have a screenshot?

Regards,
Yupei 

Pete

unread,
Sep 15, 2018, 6:41:10 AM9/15/18
to QuPath users
Possibly, but it would be complex to write and I don't think it would be a good approach... the output would depend on the current window size & requires manually opening every image in the viewer, which shouldn't be necessary for batch processing.

Better to script the export directly, but then it's necessary to define exactly what you want to export, the resolution, the way objects are painted (color, opacity, line thickness) etc.  I can think of different reasons you might want to do an export like this, but the most appropriate script in each case could be different - and I don't know what it is that you need.

Pete

unread,
Sep 15, 2018, 7:26:13 AM9/15/18
to QuPath users

Yupei Yang

unread,
Sep 18, 2018, 4:20:31 PM9/18/18
to QuPath users
Thanks Pete! That's a perfect solution!
I was thinking that the output generated is from the current viewer, which means I have to click the image processed, right?
How about doing batch processing? 

Pete

unread,
Sep 19, 2018, 1:26:46 PM9/19/18
to QuPath users
Yes, without the viewer it's a bit different.

You can replace
def server = viewer.getServer()
with this
def imageData = getCurrentImageData()
def server = imageData.getServer()

However, that alone won't be enough because 
viewer.getOverlayLayers().toList()
will of course be dependent on the image currently open, because the current overlay within the viewer is based on the current image data open in that viewer.

You could start working with overlays directly (e.g. HierarchyOverlay) but then it might be better to work with painting independently of overlays (since overlays are really intended for the viewer... and you'd now be trying to avoid the viewer here).

Basically, anything should be possible - but it requires defining exactly what you want.  Hopefully the above script and these hints help give a starting point in the QuPath code.
Reply all
Reply to author
Forward
0 new messages