standardize an image

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

standardize an image

Stanislav Aggerwal
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
Reply | Threaded
Open this post in threaded view
|

Re: standardize an image

Michael Schmid
Hi Stanislav,

looks like a task for a simple macro:

run("32-bit");  //convert to floating-point data
setThreshold(1e-30, 1e30);
run("Create Selection");  //select only pixels with value>0
getStatistics(area, mean, min, max, std);
run("Subtract...", "value=&mean");
run("Divide...", "value=&std");
run("Max...", "value=4.5");  //limit pixel values
run("Min...", "value=-4.5");
resetMinAndMax();  //display actual range of pixel values
//setMinAndMax(-4.5000, 4.5000); //alternatively, use this for 0-255
run("Conversions...", "scale weighted"); //use displayed range
run("8-bit"); //Conversion to to 8 bits per pixel

If you want to keep the original image, duplicate it before starting.
To determine how to do this in a macro, use Process>Macros>Record and do the operation manually.

Michael
________________________________________________________________


On Oct 9, 2013, at 16:55, 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
Reply | Threaded
Open this post in threaded view
|

Re: standardize an image

Stanislav Aggerwal
In reply to this post by Stanislav Aggerwal
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
Reply | Threaded
Open this post in threaded view
|

Re: standardize an image

Stanislav Aggerwal
In reply to this post by Michael Schmid
Thanks very much Michael!

best,
Stan


On Wed, Oct 9, 2013 at 6:59 PM, Michael Schmid <[hidden email]>wrote:

> Hi Stanislav,
>
> looks like a task for a simple macro:
>
> run("32-bit");  //convert to floating-point data
> setThreshold(1e-30, 1e30);
> run("Create Selection");  //select only pixels with value>0
> getStatistics(area, mean, min, max, std);
> run("Subtract...", "value=&mean");
> run("Divide...", "value=&std");
> run("Max...", "value=4.5");  //limit pixel values
> run("Min...", "value=-4.5");
> resetMinAndMax();  //display actual range of pixel values
> //setMinAndMax(-4.5000, 4.5000); //alternatively, use this for 0-255
> run("Conversions...", "scale weighted"); //use displayed range
> run("8-bit"); //Conversion to to 8 bits per pixel
>
> If you want to keep the original image, duplicate it before starting.
> To determine how to do this in a macro, use Process>Macros>Record and do
> the operation manually.
>
> Michael
> ________________________________________________________________
>
>
> On Oct 9, 2013, at 16:55, 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
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: standardize an image

Leon Espinosa-3
If I can make a whish... this feature could be very useful in the "Process/Enhance Contrast..." menu, and of course with all the stacks possibilities (i.e. use stack histogram...).  :-)

All the best, Leon



Le 10 oct. 2013 à 09:52, Stanislav Aggerwal a écrit :

> Thanks very much Michael!
>
> best,
> Stan
>
>
> On Wed, Oct 9, 2013 at 6:59 PM, Michael Schmid <[hidden email]>wrote:
>
>> Hi Stanislav,
>>
>> looks like a task for a simple macro:
>>
>> run("32-bit");  //convert to floating-point data
>> setThreshold(1e-30, 1e30);
>> run("Create Selection");  //select only pixels with value>0
>> getStatistics(area, mean, min, max, std);
>> run("Subtract...", "value=&mean");
>> run("Divide...", "value=&std");
>> run("Max...", "value=4.5");  //limit pixel values
>> run("Min...", "value=-4.5");
>> resetMinAndMax();  //display actual range of pixel values
>> //setMinAndMax(-4.5000, 4.5000); //alternatively, use this for 0-255
>> run("Conversions...", "scale weighted"); //use displayed range
>> run("8-bit"); //Conversion to to 8 bits per pixel
>>
>> If you want to keep the original image, duplicate it before starting.
>> To determine how to do this in a macro, use Process>Macros>Record and do
>> the operation manually.
>>
>> Michael
>> ________________________________________________________________
>>
>>
>> On Oct 9, 2013, at 16:55, 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
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: standardize an image

Leon Espinosa-3
In reply to this post by Stanislav Aggerwal
"a wish" of course...


Le 10 oct. 2013 à 09:52, Stanislav Aggerwal a écrit :

> Thanks very much Michael!
>
> best,
> Stan
>
>
> On Wed, Oct 9, 2013 at 6:59 PM, Michael Schmid <[hidden email]>wrote:
>
>> Hi Stanislav,
>>
>> looks like a task for a simple macro:
>>
>> run("32-bit");  //convert to floating-point data
>> setThreshold(1e-30, 1e30);
>> run("Create Selection");  //select only pixels with value>0
>> getStatistics(area, mean, min, max, std);
>> run("Subtract...", "value=&mean");
>> run("Divide...", "value=&std");
>> run("Max...", "value=4.5");  //limit pixel values
>> run("Min...", "value=-4.5");
>> resetMinAndMax();  //display actual range of pixel values
>> //setMinAndMax(-4.5000, 4.5000); //alternatively, use this for 0-255
>> run("Conversions...", "scale weighted"); //use displayed range
>> run("8-bit"); //Conversion to to 8 bits per pixel
>>
>> If you want to keep the original image, duplicate it before starting.
>> To determine how to do this in a macro, use Process>Macros>Record and do
>> the operation manually.
>>
>> Michael
>> ________________________________________________________________
>>
>>
>> On Oct 9, 2013, at 16:55, 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
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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