qupath / qupath

QuPath - Open-source bioimage analysis for research
https://qupath.github.io
GNU General Public License v3.0
1.04k stars 280 forks source link

Saving Pictures (png or jpg) of Single TMA cores from TMA-dearraying? #317

Closed Cocomolch4000 closed 5 years ago

Cocomolch4000 commented 5 years ago

Hi everyone :)

I was wondering if there exists maybe a simple groovy or imageJ script for saving a png or jpg picture of each core from the TMA-dearraying?

Best Cocomolch

Svidro commented 5 years ago

I think the Export TMA data menu option generates small images as overviews, is that what you are looking for? Or something larger? With or without overlays?

Svidro commented 5 years ago

A lot more information here: https://github.com/qupath/qupath/issues/97

Cocomolch4000 commented 5 years ago

Thank you so much! In the best case I would like to have a downsampling factor of 1, so larger! Maybe I was too dumb to see it, because I already had this issue open, but this:

import javax.imageio.ImageIO
import qupath.lib.regions.RegionRequest

// Define resolution - 1.0 means full size
double downsample = 1.0

// Create output directory inside the project
def dirOutput = buildFilePath(PROJECT_BASE_DIR, 'cores')
mkdirs(dirOutput)

// Write the cores
def server = getCurrentImageData().getServer()
def path = server.getPath()
for (core in getTMACoreList()){
    // Stop if Run -> Kill running script is pressed   
    if (Thread.currentThread().isInterrupted())
        break
    // Write the image
    img = server.readBufferedImage(RegionRequest.createInstance(path, downsample, core.getROI()))
    ImageIO.write(img, 'PNG', new File(dirOutput, core.getName() + '.png'))
}
print('Done!')

is basically what I am searching for, isn't it (I never programmed Java or Groovy)? This posted Pete in Issue 97.

One further question: To execute this within QuPath's Script editor, do I have to install something before?

Best

petebankhead commented 5 years ago

No need to install anything extra to run scripts, but you can also just change the downsample for TMA export in the preferences.

Please use the forum at https://forum.image.sc/tags/qupath for questions as described whenever you try to create an issue here... it helps keep the answers in one, searchable place. GitHub issues is intended just for bugs.

petebankhead commented 5 years ago

There's more info in scripts on the wiki, including https://github.com/qupath/qupath/wiki/Writing-custom-scripts

Cocomolch4000 commented 5 years ago

Thank you so much! Sorry, I am just starting to see how much QuPath is capable of. Your code I cited from Issue 97 is the right one for my problem? Sorry and thank you all again!

petebankhead commented 5 years ago

I think so, it's probably the most relevant link. But it can vary depending on what exactly you want, e.g.

I'd suggest giving it a try, and starting a thread at https://forum.image.sc/tags/qupath if more customization is needed.

Cocomolch4000 commented 5 years ago

I am working with brightfield H&E stained TMAs, which I want to import to Matlab as my whole analysis is in Matlab. I do not need to store the pixelsize in my image, neither compression. I am using 0.2 and find it very nice! :) Thanks for your help, I will try it now!

(Btw. I have developed an algorithm which segments nuclei of mammary glands in Matlab, as ordinary watershed (also merged results from watershed with different scales) fails there, if you are interested in it I can send you the code, which is unfortunately, as mentioned earlier, not written in Java.)

Cocomolch4000 commented 5 years ago

Works perfectly, thank you! One last question: As your color deconvolution works somehow faster than mine, is there a way to export the H-channel of single cores?

petebankhead commented 5 years ago

It's certainly possible by scripting, but it involves digging deeper into the code - which I'm currently refactoring extensively, so a script written now might not work without changed when the refactoring is done. Also, the color deconvolution in QuPath produces a 32-bit result so the file format would need to be changed accordingly (e.g. to ImageJ TIFF).

I'll close this issue: please do post any further questions on the forum so that any answers are easier to find. I will soon go through all the GitHub issues that are not active issues/bugs to close them.

petebankhead commented 5 years ago

During my flurry of closing, I also saw this: https://github.com/qupath/qupath/issues/202 Posting here for reference, as the solution may involve that and pieces of ColorDeconvolutionIJ...