0

I'm completely new to groovy and have only limited experience in writing ImageJ macros, so this might be a really easy problem to fix, but here goes:

I have a 5D hyperstack (3 channels, 3 slices, ~100 stage positions) which suffer from a highly uneven illumination. I have found a rather straightforward formula for correcting for this. The formula is

C = (R-D)*m/(F-D)

where C is the corrected image, R is the raw image, D is the dark-field image, F is the flat-field image and m is the image-averaged value of (F-D).

For single-channel 3D images (x, y, p) this is relatively straight-forward and does not need any macro scripting, but for multi-channel, multi-slice 5D images, I would have to at the very least split the image into individual channels before I can apply the correction formula to each channel and then recombine them. I have been trying to write a macro using groovy to handle this for me (I chose groovy because I was told it was more user-friendly, so I'm open to other suggestions), but I can't seem to get it running. Currently, I have the code below (I left out the dark-field because my images are already corrected for this during acquisition):

import ij.*
import ij.plugin.filter.ImageMath
import ij.process.*
import ij.gui.*
import java.awt.*
import ij.plugin.*

class My_Plugin implements PlugIn {

    void run(java.lang.String arg) {
        ImagePlus flatfield = WindowManager.getImage("flatfield.tif")
        ImagePlus rawstack = WindowManager.getImage("Untitled.tif")
        ImagePlus correctedstack = IJ.createImage("HyperStack", "32-bit composite-mode", 512, 512, 3, rawstack.z, 1)
        float m;
        for (c in flatfield.c) {
            flatfield.setC(c)
            rawstack.setC(c)
            correctedstack.setC(c)
            m = flatfield.getStatistics().mean
            rawstack.z.each { z ->
                rawstack.setZ(z)
                correctedstack.setZ(z)
                if (m > 0) {
                    rawstack.processor.multiply(m)
                    correctedstack.processor.divide(flatfield)
                }
            }
        }
        correctedstack.show()
    }

}

new My_Plugin().run()

This code currently fails with the following exception (but I suspect the code itself is generally poorly written):

groovy.lang.MissingMethodException: No signature of method: ij.process.FloatProcessor.divide() is applicable for argument types: (ij.CompositeImage) values: [img["flatfield.tif" (-274), 8-bit, 512x512x3x3x1]] Possible solutions: dilate(), dilate(), erode(), erode(), find(), noise(double)

Any help is greatly appreciated!

Bjarne Thorsted
  • 117
  • 1
  • 11

1 Answers1

0

I can just explain the Groovy error you encounter, not how to fix your implementation of the correction formula. It says that FloatProcessor doesn't have a method with the below signature. Neither its own nor inherited nor through other Groovy mechanics, e.g. MOP, AST or Extensions

divide(ij.CompositeImage img)

The ImageJ's source code confirms that neither FloatProcessor nor its superclass ImageProcessor don't have such a method.

Dmitry Khamitov
  • 3,061
  • 13
  • 21