Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
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 |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
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 ... [show rest of quote]
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by RuhlAlex
On Friday 26 June 2009 09:31:20 Alex Ruhl wrote:
> int p = ip.getPixel(u,v); > if (p<0) {ip.putPixel(u,v,(p+180));} You are trying to store a 32bit value in an integer. You also need to look at the API, I think that for 32bits the method is called getPixelValue. Cheers G. |
Free forum by Nabble | Disable Popup Ads | Edit this page |