Login  Register

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

Posted by ctrueden on Apr 06, 2015; 2:51pm
URL: http://imagej.273.s1.nabble.com/Java-codes-for-RGB-images-does-not-work-for-ImageJ-2-tp5012360p5012364.html

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