ImageJ as library

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

ImageJ as library

dashko
Hi,
I am using ImageJ as library and need some help. So i have jPanel1 in my jFrame and i need import brightness/contrast functions and link these functions with my opened image. This is my implementation:

///////////////////////////////////////////////////////////////////////////////////////
        Graphics g = this.jPanel1.getGraphics();
        Point p = new Point(0,0);

        ImagePlus imp = IJ.openImage("/home/dashko/imgs/.obrazok.temp/obrazok4.jpg");
        ColorProcessor cp = (ColorProcessor) imp.getProcessor();
        int[] pixels = (int[]) cp.getPixels();
        BufferedImage bimg = new BufferedImage(cp.getWidth(),cp.getHeight(),BufferedImage.TYPE_INT_RGB);
        bimg.setRGB(0,0,cp.getWidth(),cp.getHeight(),pixels,0,cp.getWidth());

        g.drawImage(bimg, p.x, p.y, this.jPanel1);
///////////////////////////////////////////////////////////////////////////////////////      

So question: How can i change brightness and contrast in my jPanel1 image using ImageJ library?
Is there some doc with examples of using ImageJ as library?

I tried almost everything. Creating new objects of ContrastAdjuster, copying pieces of code in my jFrame. I think something very important is missing me. Please help me!

Or maybe you will tell me about another better library to process images easyli with examples?

Thank you very much.
Mike
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ as library

Volker Baecker
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,
as long as you use the framework provided by ImageJ you can use the
method ImageProcessor>setMinAndMax().

I think there are multiple problems with your code that are not related
to ImageJ.

You need to create a subclass of JPanel that overrides one of the paint
methods to draw on the graphics. Otherwise each update of the window
content will overwrite image you have drawn on the graphics.

I thin that when you set the pixels in the buffered image the pixel
array is copied not set as a reference. Subsequent changes to the pixels
values in the array will therefore not be reflected in the image.

I suppose there is a reason you want to draw your image in a panel
otherwise you could just stay with the ImagePlus where everything is
automatic.

You might find the following example helpful:

public class ImagePanel extends JPanel {
       
        public ImagePlus imp;
        public BufferedImage bimg;
        public int width;
        public int height;

        public static void main(String[] args) {
                ImagePanel panel = new ImagePanel();
                panel.setBounds(0, 0, panel.width, panel.height);
                JFrame win = new JFrame();
                win.setBounds(0, 0, panel.width, panel.height);
                win.add(panel);
                win.setVisible(true);
                new WaitForUserDialog("click OK.").show();
                panel.setMinAndMax(255, 255);
                panel.bimg.setRGB(0,0,panel.width, panel.height, (int[])
panel.imp.getProcessor().getPixels(),0,panel.width);
                win.repaint();
                new WaitForUserDialog("click OK.").show();
                System.exit(0);
        }
       
        public ImagePanel() {
                 imp = IJ.openImage("/media/DONNEES/file-source/Volker
Bäcker/01/stripes.tif");
                 ColorProcessor cp = (ColorProcessor) imp.getProcessor();
                 width = cp.getWidth();
                 height = cp.getHeight();
                 int[] pixels = (int[]) cp.getPixels();
             bimg = new
BufferedImage(cp.getWidth(),cp.getHeight(),BufferedImage.TYPE_INT_RGB);
             bimg.setRGB(0,0,cp.getWidth(),cp.getHeight(),pixels,0,cp.getWidth());
               
        }
       
        public void setMinAndMax(double min, double max) {
                imp.getProcessor().setMinAndMax(min, max);
                this.bimg.setRGB(0,0,width, height, (int[])
imp.getProcessor().getPixels(),0, width);
                this.repaint();
        }
       
         protected void paintComponent(Graphics g) {
                int x = (getWidth() - width)/2;
                int y = (getHeight() - height)/2;
                g.drawImage(bimg, x, y, this);
         }
}



dashko wrote:

> Hi,
> I am using ImageJ as library and need some help. So i have jPanel1 in my
> jFrame and i need import brightness/contrast functions and link these
> functions with my opened image. This is my implementation:
>
> ///////////////////////////////////////////////////////////////////////////////////////
>         Graphics g = this.jPanel1.getGraphics();
>         Point p = new Point(0,0);
>
>         ImagePlus imp =
> IJ.openImage("/home/dashko/imgs/.obrazok.temp/obrazok4.jpg");
>         ColorProcessor cp = (ColorProcessor) imp.getProcessor();
>         int[] pixels = (int[]) cp.getPixels();
>         BufferedImage bimg = new
> BufferedImage(cp.getWidth(),cp.getHeight(),BufferedImage.TYPE_INT_RGB);
>        
> bimg.setRGB(0,0,cp.getWidth(),cp.getHeight(),pixels,0,cp.getWidth());
>
>         g.drawImage(bimg, p.x, p.y, this.jPanel1);
> ///////////////////////////////////////////////////////////////////////////////////////      
>
> So question: How can i change brightness and contrast in my jPanel1 image
> using ImageJ library?
> Is there some doc with examples of using ImageJ as library?
>
> I tried almost everything. Creating new objects of ContrastAdjuster, copying
> pieces of code in my jFrame. I think something very important is missing me.
> Please help me!
>
> Or maybe you will tell me about another better library to process images
> easyli with examples?
>
> Thank you very much.
> Mike
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkuaI90ACgkQ0gXPLVKexCcSyACfarUV80zq66GOKO5bCx9ORTi9
1i4An2vp9j6qO3dLSe8TgqzDUf+pRpjM
=jmym
-----END PGP SIGNATURE-----

--
passerelle antivirus du campus CNRS de Montpellier
--
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ as library

dashko
Thanks a lot. It worked perfect!