[vtkusers] How do we change brightness and contrast in a Image?

Rodrigues, Jason (MED) JasonR at geind.ge.com
Tue Feb 19 04:33:13 EST 2002


Hello all,
I have a basic query, I am sure youll be in a position to guide me better. 
How do I change the brightness and contrast of a image stored in
vtkImageData Object? What is the pipe line to render the same on to a panel
or window? 



import vtk.*;
import javax.swing.*;
import java.awt.event.*;

public class ImageDataDisplay {
   vtkImageData imagedata;
   JFrame mainframe;
   vtkPanel panel;
   vtkColorTransferFunction  LUT1;
   vtkImageMapToColors mapToRGBA1;
    vtkImageCast cast1;
    vtkImageMapper imgMapper;
    vtkLookupTable lut;
     vtkActor2D actor;
     vtkRenderer ren;

    public ImageDataDisplay(ImageVolume iv) {
              mainframe = new JFrame("VTKPANEL");
               panel = new vtkPanel();
              panel.addMouseMotionListener(new MouseMotionAdapter(){
                  public void mouseDragged(MouseEvent me){

                      int x = me.getX();
                      int y = me.getY();
                     LUT1 = new vtkColorTransferFunction();
                      LUT1.AddRGBPoint (8000.0, 0.2, 0.2, 0.2);
                      LUT1.AddRGBPoint  ( 6424.0, 0.9, 0.9, 0.9);
                      LUT1.AddRGBPoint  (6324.0, 0.0, 0.0, 1.0);
                      LUT1.AddRGBPoint ( 6224.0, 0.0, 1.0, 0.0);
                      LUT1.AddRGBPoint    (6154.0, 1.0, 1.0, 1.0);
                      LUT1.AddRGBPoint    (2153.0, 0.8, 0.8, 0.8);
                      LUT1.AddRGBPoint    (0.0,0.5, 0.5, 0.5);
                       dorender();
                  }
              });
              mainframe.getContentPane().add(panel);
                     int slices = iv.noOfImages;
                     int height = iv.getImages(0).getHeight();
                     int width = iv.getImages(0).getWidth();
                     short[][][] vtkPix = new short[slices][height][width];

        // 
                      for(int i=0; i<iv.noOfImages; i++) {
                             ImageClass ic = iv.getImages(i);
                             super.setImage(ic);
                             int k = 0;
                             for(int j=0; j<iht; j++) {
                               for(int l=0; l<iwt; l++) {
                                short val = (short) (pixelint[k++] &
0x7fff);
                                      vtkPix[i][j][l] = val;
                                }
                            }

                      }

                 imagedata = new vtkImageData();
                  imagedata.SetWholeExtent(0,width-1,0,height-1,0,slices-1);
                  imagedata.SetExtent(0,width-1,0,height-1,0,slices-1);
 
imagedata.SetUpdateExtent(0,width-1,0,height-1,0,slices-1);
                  imagedata.SetScalarType(5);
                  imagedata.AllocateScalars();

                         int id = 0;
                         for(int i = 0; i < slices; i++) {
                            for(int j = iht-1;j >0 ; j--) {
                                  for(int k = 0; k <width; k++) {
                                         double val =
(double)vtkPix[i][j][k];
 
imagedata.GetPointData().GetScalars().SetScalar(id,val);
                                         id++;
                                  }
                              }
                          }
                     //#   create a color lookup table
            LUT1 = new vtkColorTransferFunction();
            LUT1.AddRGBPoint (0.0, 0.2, 0.2, 0.2);
            LUT1.AddRGBPoint  (2153.0, 0.9, 0.9, 0.9);
            LUT1.AddRGBPoint  (6154.0, 0.0, 0.0, 1.0);
            LUT1.AddRGBPoint ( 6224.0, 0.0, 1.0, 0.0);
            LUT1.AddRGBPoint    (6324.0, 1.0, 1.0, 1.0);
            LUT1.AddRGBPoint    (6424.0, 1.0, 0.0, 0.0);
            LUT1.AddRGBPoint    (8000.0, 2.0, 0.0, 0.0);
                          dorender();


                }

                public void dorender() {




            mapToRGBA1 = new vtkImageMapToColors();
		mapToRGBA1.SetInput(imagedata);
		mapToRGBA1.SetLookupTable(LUT1);
                mapToRGBA1.SetOutputFormatToRGBA();
                imagedata = mapToRGBA1.GetOutput();

           cast1 = new vtkImageCast ();
		cast1.SetInput(mapToRGBA1.GetOutput());
		cast1.SetOutputScalarType(5);
		imagedata= cast1.GetOutput();
                imagedata.Update();

          imgMapper = new vtkImageMapper();
             imgMapper.SetInput(imagedata);
             imgMapper.SetColorWindow(255.0);
             imgMapper.SetColorLevel(127.0);


            actor = new vtkActor2D();
                 actor.SetMapper(imgMapper);

             ren=panel.getRenderer();
                  ren.AddActor2D(actor);
                  ren.Render();




                  mainframe.addWindowListener(new WindowAdapter() {
                            public void windowClosing(WindowEvent we) {
                                 mainframe.dispose();
                            }
                    });

                        mainframe.setSize(512,  512+27);
                          mainframe.setVisible(true);
                          mainframe.setResizable(false);
                          mainframe.pack();
                          mainframe.show();



           }


 }


"THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE
ADDRESSEE and may contain confidential and privileged information.
If the reader of this message is not the intended recipient,
you are notified that any dissemination, distribution or copy of this 
communication is strictly Prohibited. 
If you have received this message by error, please notify us 
immediately, return the original mail to the sender and delete the 
message from your system."




More information about the vtkusers mailing list