normalize stack of pictures

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

normalize stack of pictures

jakudo
Hello,
I'm kind of new here and I would like to ask you for some help.
What I want to do: I have stack of pictures (around 100) which I've made in Neutron Tomography. But not all of were created by the same strong beam so some of them are more dark. I've selected some free space and run "Measure stack" in plugins. It gave me means of each picture. Now I need to divide each picture by the mean value. I don't know whether there is some plugin for that, but I didn't find one. I've also tried to create some macro, but not so successfully.
Can anybody help me with it please?

Thanks
Jakub
Reply | Threaded
Open this post in threaded view
|

Re: normalize stack of pictures

jmutterer
Jakub,

The following macro should do what you describe.
Jerome


run("32-bit");
run ("Select None");
for(i=1; i<=nSlices; i++) {
setSlice(i);
v = getResult("Mean1",i-1);
run("Divide...", "value=&v");
}
resetMinAndMax();


On Wed, Feb 17, 2010 at 11:13 AM, jakudo <[hidden email]> wrote:

> Hello,
> I'm kind of new here and I would like to ask you for some help.
> What I want to do: I have stack of pictures (around 100) which I've made in
> Neutron Tomography. But not all of were created by the same strong beam so
> some of them are more dark. I've selected some free space and run "Measure
> stack" in plugins. It gave me means of each picture. Now I need to divide
> each picture by the mean value. I don't know whether there is some plugin
> for that, but I didn't find one. I've also tried to create some macro, but
> not so successfully.
> Can anybody help me with it please?
>
> Thanks
> Jakub
> --
> View this message in context:
> http://n2.nabble.com/normalize-stack-of-pictures-tp4585257p4585257.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: normalize stack of pictures

jakudo
Thanks a lot!!! It works exactly as I wanted:)
Reply | Threaded
Open this post in threaded view
|

Re: normalize stack of pictures

Zian_Fanti
In reply to this post by jakudo
if you still need here is an implementation of one normalization method

You must compile the plugin before use.

To use the plugin:
1.- Open a stack or sequence
2.- select a good ilumination frame to use as reference
3.- run the plugin

The plugin

import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.plugin.filter.PlugInFilter;
import ij.process.FloatStatistics;
import ij.process.ImageProcessor;
import utils.IOUtils;

/**
 *
 * @author <a ref ="[hidden email]"> Zian Fanti Gutierrez<a/>
 * @version 0.1
 */
public class Normalize_Ilumination_1 implements PlugInFilter {

    private ImagePlus imp;
    private int currentFrame;

    public int setup(String arg0, ImagePlus imp) {
        if (imp == null)
            IJ.noImage();
        this.imp = imp;
        currentFrame = imp.getCurrentSlice();
        return DOES_8G;
    }


    public void run(ImageProcessor ip) {
        ImagePlus out = new ImagePlus(IOUtils.windowName("Normalized
Ilumination"),
                normalizeIlumination(imp.getImageStack(), currentFrame));
        out.show("Normalize Ilumination Done");
    }

    /**
     * Return a new <code>ImageStack</code> with the normalized
ilumination. The
     * return stack is generated from original <code>stack</code>
     *
     * @param referenceIndex, the index of the frame in the original
<code>stack</code>
     * which is used as reference frame.
     * @return Return a new <code>ImageStack</code> with the normalized
ilumination.
     *
     * @Article RICHARD, J., RADKE, SRINIVAS, A., OMAR, A.K. and
BADRINATH, R., 2005,
     * Image Change Detection Algorithms: A Systematic Survey, IEEE
Transactions
     * on Image Processing, 14(3), pp.294-307.
     */
    public ImageStack normalizeIlumination(ImageStack stack, int
referenceIndex) {
        int size = stack.getSize();
        int width = stack.getWidth();
        int height = stack.getHeight();
        if (size == 1) {
            return stack;
        }

        ImageStack resultStack = new ImageStack(width, height);
        double factor = 0;

        if (referenceIndex < 0 || referenceIndex > size) {
            throw new NullPointerException();
        } else {
            ImageProcessor tmpImage = null;
            ImageProcessor referenceImage =
stack.getProcessor(referenceIndex).convertToFloat();

            FloatStatistics stats = new FloatStatistics(referenceImage);
            double RIstdv = stats.stdDev;
            double RIMean = stats.mean;

            double tmpSTDV = 0;
            double tmpMean = 0;

            for (int i = 1; i <= size; i++) {
                tmpImage = stack.getProcessor(i).convertToFloat();
                stats = new FloatStatistics(tmpImage);

                tmpSTDV = stats.stdDev;
                tmpMean = stats.mean;

                //calculate normalizated image
                factor = ((RIMean * tmpSTDV) - (tmpMean * RIstdv)) / tmpSTDV;
                double f1 = RIstdv / tmpSTDV;
                tmpImage.multiply(f1);
                tmpImage.add(factor);
                resultStack.addSlice("normalized" + i,
tmpImage.convertToByte(false));

                IJ.showProgress(i, size);
            }
        }
        return resultStack;
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: normalize stack of pictures

lechristophe
In reply to this post by jakudo
Normalization of images from a stack by the mean intensity value : isn't
that what you obtain if you do Process>Enhance Contrast and use Saturated
Pixels: 0%, with only the "Normalize all N Slices" option checked ?


On Wed, Feb 17, 2010 at 11:13, jakudo <[hidden email]> wrote:

> Hello,
> I'm kind of new here and I would like to ask you for some help.
> What I want to do: I have stack of pictures (around 100) which I've made in
> Neutron Tomography. But not all of were created by the same strong beam so
> some of them are more dark. I've selected some free space and run "Measure
> stack" in plugins. It gave me means of each picture. Now I need to divide
> each picture by the mean value. I don't know whether there is some plugin
> for that, but I didn't find one. I've also tried to create some macro, but
> not so successfully.
> Can anybody help me with it please?
>
> Thanks
> Jakub
> --
> View this message in context:
> http://n2.nabble.com/normalize-stack-of-pictures-tp4585257p4585257.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: normalize stack of pictures

jakudo
actually the first post helps me a lot and I've solved it. However, I want to learn about it more so I try to process it with the plug-in you've send me.
Thanks for it;)