[Insight-users] How GetPixel value

charfeddine amir charfeddine_amir at yahoo.fr
Mon Jan 30 04:32:02 EST 2006


Hi Mariusz,
 download the ItkSoftwareGuide.pdf from this link http://www.itk.org/ItkSoftwareGuide.pdf
 then go to section 4.1.3 Accessing Pixel Data page 38, where you will read about SetPixel() and GetPixel() method, i think that's what u need in that case.
 you have to do something like this :
 
 ImageType::IndexType pixelIndex;
 
 pixelIndex[0] = x;      // x position of the pixel
 pixelIndex[1] = y;      // y position of the pixel
 
 ImageType::PixelType      pixelValue = image->GetPixel( pixelIndex );
 
 hope that help u.
 Amir

mariusz_smch at poczta.fm a écrit : 
Hi all.

How get pixel value prom 2D DICOM Slices.
I clic on the image and have mouse coordinats from
vtkCommand:

renderWindowInteractor->GetEventPosition (x, y)

now I woul like to get pixel value but I don't know how. Do I supose to transfer coordinat x,y?
Here is peace of my code:


typedef signed short InputPixelType;
const unsigned int InputDimension = 2;
typedef itk::Image< InputPixelType, InputDimension > InputImageType;
InputImageType::Pointer image;//= InputImageType::New();
//InputImageType::PixelType   pixelValue;

vtkRenderWindowInteractor* renderWindowInteractor;
vtkImageViewer* viewer;

class vtkMyCallback : public vtkCommand
{
public:
  static vtkMyCallback *New()  
    { return new vtkMyCallback; }
  virtual void Execute(vtkObject *caller, unsigned long, void*)
    {
    vtkRenderer *renderer = reinterpret_cast(caller);
 //vtkRenderWindowInteractor* renderWindowInteractor=reinterpret_cast(caller);
 //vtkImageViewer* viewer=reinterpret_cast(caller);
 int x,y;
 renderWindowInteractor->GetEventPosition (x, y);
 float level=viewer->GetColorLevel();
 cout<<"Level: "<<<" ";
 float color_window=viewer->GetColorWindow();
 cout<<"ColorWindow: "<<<" ";
 cout<<" x: "<<<" y: "<<
 typedef itk::Image InputImageType;
 InputImageType::IndexType index; 
 index[0]=x;
 index[1]=y;
 cout<<" Index  x: "<<<"  y: "<
 signed short pixel_value;

HERE I don't kow how get the value?
         pixel_value=image->GetPixel( index );
    }
};


void vtkdisp(const char * out_dirname_c){
// typedef signed short InputPixelType;
// const unsigned int InputDimension = 2;
// typedef itk::Image< InputPixelType, InputDimension > InputImageType;
 typedef itk::ImageFileReader< InputImageType > ReaderType;
 InputImageType::PixelType   pixelValue;
         ReaderType::Pointer reader = ReaderType::New();
 reader->SetFileName(out_dirname_c);
         typedef itk::GDCMImageIO       ImageIOType;
         ImageIOType::Pointer dicomIO = ImageIOType::New();
         reader->SetImageIO(dicomIO); //reade mata data  
 try
             {
              reader->Update();
             }
         catch (itk::ExceptionObject & e)
             {
              std::cerr << "exception in file reader " << std::endl;
              std::cerr << e << std::endl;
      // return EXIT_FAILURE;
              } 
         InputImageType::Pointer image = InputImageType::New(); 
 InputImageType::IndexType indexa; 


 indexa[0]=1;
 indexa[1]=1;     <<<---do I should transfet thouse coordinat to some others??
 
 signed short  pixel_value; 
 cout<<"pixel_value---- : ";   
 pixel_value= image->GetPixel( indexa );  
 
 typedef itk::ImageToVTKImageFilter [input]  ConnectorType;
 ConnectorType::Pointer connector= ConnectorType::New();
 connector->SetInput( reader->GetOutput() );      

 //vtkImageViewer* viewer;
 viewer= vtkImageViewer::New(); 
 //vtkRenderWindowInteractor* renderWindowInteractor;
 renderWindowInteractor = vtkRenderWindowInteractor::New();      
 viewer->SetupInteractor( renderWindowInteractor);
 viewer->SetInput( connector->GetOutput() );
 viewer->Render();
 viewer->SetColorWindow(50);
 viewer->SetColorLevel(-1000);
 vtkMyCallback *mo1 = vtkMyCallback::New();
 renderWindowInteractor->AddObserver(vtkCommand::MouseMoveEvent,mo1);
 mo1->Delete();
   
 renderWindowInteractor->Start(); 
 float level=viewer->GetColorLevel();
 float color_window=viewer->GetColorWindow ();
 std::cerr<<"level:"<<
 std::cerr<<"Color window:"<<
 renderWindowInteractor->Disable 
 renderWindowInteractor->Delete();
 viewer->Delete();
};

Thanks for help
Mariusz.

----------------------------------------------------------------------
Najwiekszy czat w Polsce!!! >>> http://link.interia.pl/f18f6

_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users



		
---------------------------------
 Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international.Téléchargez la version beta.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060130/172feb59/attachment-0001.html


More information about the Insight-users mailing list