Login  Register

Re: standardize an image

Posted by Stanislav Aggerwal on Oct 10, 2013; 7:52am
URL: http://imagej.273.s1.nabble.com/standardize-an-image-tp5005105p5005120.html

Thanks very much Wayne!
Best,
Stan


On Wed, Oct 9, 2013 at 6:05 PM, Rasband, Wayne (NIH/NIMH) [E] <
[hidden email]> wrote:

> Dear Stan,
>
> Your pseudocode would look something like this as an ImageJ plugin:
>
> import ij.*;
> import ij.process.*;
> import ij.plugin.*;
>
> public class Standardize_Image implements PlugIn {
>
>     public void run(String arg) {
>         ImagePlus imp = IJ.getImage();
>         Undo.setup(Undo.TYPE_CONVERSION, imp);
>         ImageProcessor ip = imp.getProcessor();
>         ip = ip.convertToFloat();
>         int n = ip.getPixelCount();
>         ImageStatistics stats = ip.getStatistics();
>         for (int i=0; i<n; i++) {
>             double z = ip.getf(i);
>             if (z>0)
>                 z = (z-stats.mean)/stats.stdDev;
>             if (z>4.5) z=4.5;
>             if (z<-4.5) z = -4.5;
>             ip.setf(i, (float)z);
>         }
>         ip.resetMinAndMax();
>         ip = ip.convertToByte(true);
>         imp.setProcessor(ip);
>     }
>
> }
>
>
> Best regards,
>
> -wayne
> On Oct 9, 2013, at 10:55 AM, Stanislav Aggerwal wrote:
>
> > I would like to do the following, which I give below in pseudocode.
> >
> > Let's call the image z
> > znew=standardize(z)
> >
> > standardize(z)
> > {
> > zz = (z[z>0]-mean(z[z>0]))/sd(z[z>0])
> > #where z[z>0] means the pixels that have greylevels >0
> > zz[zz>4.5] = 4.5
> > zz[zz< -4.5] = -4.5
> > zz=rescale(zz, 0, 255)   #rescale the zz values to be in the range
> (0,255)
> > return(zz)
> > }
> >
> > Could someone please tell me how to do this with ImageJ/Fiji?
> >
> > Thanks very much for any help.
> >
> > Stan
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html