Java codes for RGB images does not work for ImageJ 2

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

Java codes for RGB images does not work for ImageJ 2

LIM Soon Yew John (IMB)
Dear All,

I used the Java below as part of the codes for white balance. The codes works fine in ImageJ 1.48 but it does not for ImageJ 2. Any advice on how to change it for ImageJ 2 will be greatly appreciated. Thanks. John

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.filter.PlugInFilter;

public class RGB_Color_Shift implements PlugInFilter {

        public int setup(String arg, ImagePlus imp) {
                return DOES_RGB;
        }

        public void run(ImageProcessor ip) {
                int w=ip.getWidth();
                int h=ip.getHeight();
               
                GenericDialog gd = new GenericDialog("Color Shift");
                gd.addNumericField("Red: ", 0, 0);
                gd.addNumericField("Green: ", 0, 0);
                gd.addNumericField("Blue: ", 0, 0);
                gd.showDialog();
                int red=(int) gd.getNextNumber();
                int green=(int) gd.getNextNumber();
                int blue=(int) gd.getNextNumber();
               
                int[] pixels=(int[]) ip.getPixels();

                for (int i=0; i<h; i++) {
                        int offset=i*w;
                        for (int j=0; j<w; j++) {
                                int pos=offset+j;
                                int c=pixels[pos];
                                int r=(c & 0xff0000)>>16;
                                int g=(c & 0x00ff00)>>8;
                                int b=(c & 0x0000ff);

                                r=r+red;
                                if (r<0) {r=0;}
                                if (r>255) {r=255;}
                                g=g+green;
                                if (g<0) {g=0;}
                                if (g>255) {g=255;}
                                b=b+blue;
                                if (b<0) {b=0;}
                                if (b>255) {b=255;}
                                pixels[pos]=((r  & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);
                                }
                        }
                }
}

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

Re: Java codes for RGB images does not work for ImageJ 2

ctrueden
Hi John,

> The codes works fine in ImageJ 1.48 but it does not for ImageJ 2. Any
> advice on how to change it for ImageJ 2 will be greatly appreciated.

ImageJ2 is intended to be backwards compatible with ImageJ1. So no changes
should be required. The plugin works on my system.

Can you please be more specific about how it fails on your system?
http://imagej.net/Bug_reporting_best_practices

Regards,
Curtis

On Sun, Apr 5, 2015 at 10:50 PM, LIM Soon Yew John (IMB) <
[hidden email]> wrote:

> Dear All,
>
> I used the Java below as part of the codes for white balance. The codes
> works fine in ImageJ 1.48 but it does not for ImageJ 2. Any advice on how
> to change it for ImageJ 2 will be greatly appreciated. Thanks. John
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import ij.plugin.filter.PlugInFilter;
>
> public class RGB_Color_Shift implements PlugInFilter {
>
>         public int setup(String arg, ImagePlus imp) {
>                 return DOES_RGB;
>         }
>
>         public void run(ImageProcessor ip) {
>                 int w=ip.getWidth();
>                 int h=ip.getHeight();
>
>                 GenericDialog gd = new GenericDialog("Color Shift");
>                 gd.addNumericField("Red: ", 0, 0);
>                 gd.addNumericField("Green: ", 0, 0);
>                 gd.addNumericField("Blue: ", 0, 0);
>                 gd.showDialog();
>                 int red=(int) gd.getNextNumber();
>                 int green=(int) gd.getNextNumber();
>                 int blue=(int) gd.getNextNumber();
>
>                 int[] pixels=(int[]) ip.getPixels();
>
>                 for (int i=0; i<h; i++) {
>                         int offset=i*w;
>                         for (int j=0; j<w; j++) {
>                                 int pos=offset+j;
>                                 int c=pixels[pos];
>                                 int r=(c & 0xff0000)>>16;
>                                 int g=(c & 0x00ff00)>>8;
>                                 int b=(c & 0x0000ff);
>
>                                 r=r+red;
>                                 if (r<0) {r=0;}
>                                 if (r>255) {r=255;}
>                                 g=g+green;
>                                 if (g<0) {g=0;}
>                                 if (g>255) {g=255;}
>                                 b=b+blue;
>                                 if (b<0) {b=0;}
>                                 if (b>255) {b=255;}
>                                 pixels[pos]=((r  & 0xff) << 16) + ((g &
> 0xff) << 8) + (b & 0xff);
>                                 }
>                         }
>                 }
> }
>
> --
> 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: Java codes for RGB images does not work for ImageJ 2

LIM Soon Yew John (IMB)
Hi Curtis,

Thanks for the guideline on bug reporting. I will follow it in the future.

And thanks to you, the issue was my copy of ImageJ 2. I had downloaded a fresh copy and it is working.

Best Regards,
John

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Curtis Rueden
Sent: Monday, 6 April, 2015 10:51 PM
To: [hidden email]
Subject: Re: Java codes for RGB images does not work for ImageJ 2

Hi John,

> The codes works fine in ImageJ 1.48 but it does not for ImageJ 2. Any
> advice on how to change it for ImageJ 2 will be greatly appreciated.

ImageJ2 is intended to be backwards compatible with ImageJ1. So no changes should be required. The plugin works on my system.

Can you please be more specific about how it fails on your system?
http://imagej.net/Bug_reporting_best_practices

Regards,
Curtis

On Sun, Apr 5, 2015 at 10:50 PM, LIM Soon Yew John (IMB) < [hidden email]> wrote:

> Dear All,
>
> I used the Java below as part of the codes for white balance. The
> codes works fine in ImageJ 1.48 but it does not for ImageJ 2. Any
> advice on how to change it for ImageJ 2 will be greatly appreciated.
> Thanks. John
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import ij.plugin.filter.PlugInFilter;
>
> public class RGB_Color_Shift implements PlugInFilter {
>
>         public int setup(String arg, ImagePlus imp) {
>                 return DOES_RGB;
>         }
>
>         public void run(ImageProcessor ip) {
>                 int w=ip.getWidth();
>                 int h=ip.getHeight();
>
>                 GenericDialog gd = new GenericDialog("Color Shift");
>                 gd.addNumericField("Red: ", 0, 0);
>                 gd.addNumericField("Green: ", 0, 0);
>                 gd.addNumericField("Blue: ", 0, 0);
>                 gd.showDialog();
>                 int red=(int) gd.getNextNumber();
>                 int green=(int) gd.getNextNumber();
>                 int blue=(int) gd.getNextNumber();
>
>                 int[] pixels=(int[]) ip.getPixels();
>
>                 for (int i=0; i<h; i++) {
>                         int offset=i*w;
>                         for (int j=0; j<w; j++) {
>                                 int pos=offset+j;
>                                 int c=pixels[pos];
>                                 int r=(c & 0xff0000)>>16;
>                                 int g=(c & 0x00ff00)>>8;
>                                 int b=(c & 0x0000ff);
>
>                                 r=r+red;
>                                 if (r<0) {r=0;}
>                                 if (r>255) {r=255;}
>                                 g=g+green;
>                                 if (g<0) {g=0;}
>                                 if (g>255) {g=255;}
>                                 b=b+blue;
>                                 if (b<0) {b=0;}
>                                 if (b>255) {b=255;}
>                                 pixels[pos]=((r  & 0xff) << 16) + ((g
> &
> 0xff) << 8) + (b & 0xff);
>                                 }
>                         }
>                 }
> }
>
> --
> 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