Re: calculation on 32bit pictures

Posted by Michael Schmid on
URL: http://imagej.273.s1.nabble.com/calculation-on-32bit-pictures-tp3691981p3691983.html

Hi Alex,

getPixel gets an integer value that has the same bit pattern as the  
float number - not very useful for float calculations. Use  
getPixelValue, putPixelValue or directly the pixels array:

float[] pixels = (float[])ip.getPixels();
for (int i=0; i<pixels.length; i++)
     if (pixels[i] < 0) pixels[i] += 180;


Michael
________________________________________________________________

On 26 Jun 2009, at 11:10, Alex Ruhl wrote:

> Hi,
>
> I have 32 Bit-images with negative values. I want to add a value to  
> these
> pixels to get them positive.
>
> I tried to modify the MyInverter plugin (below) but didnt succeed.
> What do I have to modify to calculate with floating point values?
> I dont get the right values by using getpixel and putpixel.
> Is this only for int-values?
>
> ----------------------------------------------------------------------
> --
> import ij.ImagePlus;
> import ij.plugin.filter.PlugInFilter;
> import ij.process.ImageProcessor;
>
> /* W. Burger, M. J. Burge: "Digitale Bildverarbeitung"
> * � Springer-Verlag, 2005
> * www.imagingbook.com
> */
>
> public class MyInverter_ implements PlugInFilter {
>
>    public int setup(String arg, ImagePlus img) {
>        return DOES_32;    // this plugin accepts 8-bit grayscale  
> images
>    }
>
>    public void run(ImageProcessor ip) {
>        int w = ip.getWidth();
>        int h = ip.getHeight();
>
>        for (int u = 0; u < w; u++) {
>            for (int v = 0; v < h; v++) {
>                int p = ip.getPixel(u,v);
>               if (p<0) {ip.putPixel(u,v,(p+180));}
>            }
>        }
>    }
>           }
>
>
> -----------------------------
>
> Thanks for help,
>
> Alex