Help with output of ParticleAnalyzer and Bioformats



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)
            particlestack = ImageStack(imp.getWidth(), imp.getHeight())

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

            return particlestack

    def BFExport(imp, savepath):

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

        return None

# Analyze particles with a filter on the size and circularity
# These values can also be changed, "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, "Bio-Formats Exporter", "save=[" + savepath + "] export compression=Uncompressed")
#IJ.saveAs(maskImp, "Tiff", savepath);    
maskImp.close()"Close All")

Thanks for your help !


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.





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