We're Hiring!

jython script setShowROIs

Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats
Please note:
Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats

If you are having trouble with image files, there is information about reporting bugs in the Bio-Formats documentation. Please send us the data and let us know what version of Bio-Formats you are using. For issues with your code, please provide a link to a public repository, ideally GitHub.

jython script setShowROIs

Postby ebbwdan » Fri Feb 20, 2015 4:56 am

Hi

I am writing a fairly simple Jython script to run in headless mode in Fiji and have run into a problem. I have generated an OME-TIFF from some custom code where I have written a polygon ROI into the OME-XML. I want to open the image and display the ROI. I have the following in my script:

Code: Select all
from loci.common import Region
from loci.plugins.in import ImporterOptions
options = ImporterOptions()
options.setShowROIs(True)
options.setColorMode(ImporterOptions.COLOR_MODE_COLORIZED)
options.setId(file)
imps = BF.openImagePlus(options)
for imp in imps:
   imp.show()


But the ROI Manager never opens for the ROI to be selected.

When I try this using the Bioformats Importer it works just fine. I must have missed something!

Cheers,

Dan.
ebbwdan
 
Posts: 61
Joined: Wed Aug 29, 2012 4:46 am

Re: jython script setShowROIs

Postby jburel » Fri Feb 20, 2015 11:15 am

Hi Dan
The showROIs and showOMEXML options are not supported in BF
so nothing wrong with your code: note that you don't need ``from loci.common import Region``, unless you are using it elsewhere
I have opened a Pull Request to address the issue (see https://github.com/openmicroscopy/bioformats/pull/1617)

Thanks for pointing that out.

Cheers
Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: jython script setShowROIs

Postby ebbwdan » Sat Feb 21, 2015 7:29 am

Hi JMarie,

Perhaps I should have checked the source code! Anyway, I made it work by dumping the xml and then getting the ROI from the resultant string.

After parsing I create an ROI and process it:

Code: Select all
from ij.gui import Roi, PolygonRoi

proi = PolygonRoi(xs, ys, len(xs), Roi.POLYGON) 
for i,imp in enumerate(imps):
    print i
    imp.setRoi(proi)
    ip = imp.getProcessor()
    ip.fillOutside(proi)


Then I would like to export the result as OME-TIFF. I tried the easy approach:

Code: Select all
ij.run(imp,"Bio-Formats Exporter", "save=[%s] compression=LZW");


But this gives me:

java.lang.NullPointerException
at net.imagej.patcher.EssentialLegacyHooks.missingSubdirectories(EssentialLegacyHooks.java:164)


I tried using the LociExporter class but I can't seem to make it work without the saveAs GUI popping up. Should I be using the ImageWriter class to do this? Which will require me to "saveBytes" for each plane?

Am I asking this in the right place? Or is this an ImageJ question?

Any advice will be gratefully received!

Cheers,

Dan.
ebbwdan
 
Posts: 61
Joined: Wed Aug 29, 2012 4:46 am

Re: jython script setShowROIs

Postby jburel » Mon Feb 23, 2015 1:51 pm

Hi Dan
I had a look at the code and there is no option to save w/o the dialog popping up.
I will push a fix

For the exception you posted it seems to be related to the legacy layer so I assume you are using ImageJ2.
This is more an ImageJ question

Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: jython script setShowROIs

Postby ebbwdan » Tue Feb 24, 2015 4:47 am

Hi Jmarie,

Thanks for the feedback. For the record I solved it by using Bioformats as a library in my script:

Code: Select all
writer = ImageWriter()
writer.setMetadataRetrieve(omeMeta)
writer.setId('%s')

# get the stack
planes = imp.getStack()
for p in range(planes.getSize()):

    # get the plane
    plane = planes.getProcessor(p+1)
   
    # fill outside
    plane.fillOutside(proi)
   
    pixels = plane.convertToByte(True).getPixels()
    writer.saveBytes(p,pixels)
   
reader.close()
writer.close()


The reason for this is that I want to run ImageJ (Fiji) for server-side processing. I have a script which:
1. gets Omero ROIs
2 writes them to OME-XML
3 writes the OME-TIFF
4 uses Fiji to process
5 ingests the results of processing using the command line importer

Cheers,

Dan.
ebbwdan
 
Posts: 61
Joined: Wed Aug 29, 2012 4:46 am

Re: jython script setShowROIs

Postby jburel » Tue Feb 24, 2015 1:24 pm

Hi Dan

Thanks for the information
Actually, in develop, we have already modified the exporter so you can save the image as ome-tiff w/o dialog popping up.
you will have to specify all the parameters. That could be simplified
Follow some java code we use to generate an ome-tiff of a modified image before import to OMERO.
Code: Select all
StringBuffer buffer = new StringBuffer();
buffer.append("outfile="+f.getAbsolutePath());
buffer.append(" splitz=false");
buffer.append(" splitc=false");
buffer.append(" splitt=false");
buffer.append(" saveroi=true");
buffer.append(" compression="+CompressionType.UNCOMPRESSED.getCompression());
buffer.append(" imageid="+img.getID()+" "); //imageJ image ID
IJ.runPlugIn("loci.plugins.LociExporter", buffer.toString());

The change will be available in the coming 5.1 version.

Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee


Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 1 guest