Help with output of ParticleAnalyzer and Bioformats

jython
bioformats
analyze-particles
imagej
Tags: #<Tag:0x00007fd542e7fbc0> #<Tag:0x00007fd542e7fa80> #<Tag:0x00007fd542e7f940> #<Tag:0x00007fd542e7f760>

#1

Hi all,

I am writing a simple code to pre process data then use Analyze Particles to filter out the smallest particles and save the result mask as ome.tiff using BioFormats.

For some reasons, when exporting using BioFormats, what is saved is the image before Analyze Particles and not the result. I’ve been trying different things based on results from the forum etc but I can’t find the solution… I tried using saveAs and that works but it loses the metadata.

Here’s the current code:

    def analyzeParticles(imp):

            MINSIZE = 0.8
            MAXSIZE = 10000000000
            MINCIRC = 0
            MAXCIRC = 0.6

            options = PA.SHOW_MASKS \

            measurements = PA.STACK_POSITION \
                + PA.LABELS \
                + PA.AREA \
                + PA.RECT \

            results = ResultsTable()

            p = PA(options, measurements, results, MINSIZE, MAXSIZE, MINCIRC, MAXCIRC)
            p.setHideOutputImage(True)
            particlestack = ImageStack(imp.getWidth(), imp.getHeight())

            for i in range(imp.getStackSize()):
                imp.setSliceWithoutUpdate(i + 1)
                ip = imp.getProcessor()
                #IJ.run(imp, "Convert to Mask", "")
                p.analyze(imp, ip)
                mmap = p.getOutputImage()
                particlestack.addSlice(mmap.getProcessor())

            return particlestack

    def BFExport(imp, savepath):

        print('Savepath: ', savepath)
        plugin = LociExporter()
        plugin.arg = savepath
        exporter = Exporter(plugin, imp)
        exporter.run() 

        return None

# Analyze particles with a filter on the size and circularity
# These values can also be changed
#IJ.run(imp, "Analyze Particles...", "size=0.8-Infinity pixel circularity=0.00-0.60 show=Masks stack")

maskStack = analyzeParticles(imp)
maskImp = ImagePlus('Mask',maskStack)

# save as OME-TIFF
IJ.run(maskImp, "Bio-Formats Exporter", "save=[" + savepath + "] export compression=Uncompressed")
#IJ.saveAs(maskImp, "Tiff", savepath);    
                
maskImp.close()
IJ.run("Close All")

Thanks for your help !


#2

Good day,

it’s always a good idea to provide a minimal example (MCVE: minimal, complete, and verifiable example) because it increases the likelihood that someone will look for a solution of your problem.

Regards

Herbie


#3

Hello,

Makes sense, I’ll edit my post to filter out the non useful part :wink: