[Insight-users] How GetPixel value

charfeddine amir charfeddine_amir at yahoo.fr
Tue Jan 31 03:48:15 EST 2006


Hi Mariusz
 u write :
 (...)
 reader->Update();
 (...)
 InputImageType::Pointer image = InputImageType::New(); 
 InputImageType::IndexType index; 
 
 index[0]=1;
 index[1]=1; 
 
 signed short pixel_value; 
 
 /***********************************************
 Here , your variable image is not yet initialized with something, so it's normal that program crash
 i think u should add a line like this :
 **********************************************/
 image=reader->GetOuput();
 //then get the pixel value
 pixel_value= image->GetPixel( index );   <-her program crash
 cout<<"pixel_value : "<<
 (...)
 
 hope this resolve your problem
 Let us know what happen,
 Amir,

mariusz_smch at poczta.fm a écrit : Hi Amir

I did read ItkSoftwareGuide.pdf and try to do as you can see very similar to this, but still don't know whot's wrong when I try do someting like this:

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->Update();
(...)
InputImageType::Pointer image = InputImageType::New(); 
InputImageType::IndexType index; 

index[0]=1;
index[1]=1; 

signed short pixel_value; 
pixel_value= image->GetPixel( indexa );   <-her program crash
cout<<"pixel_value : "<
<
(...)

Can anyone sugest whot I did wrong.
Thanks Mariusz.



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 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.


----------------------------------------------------------------------
Najnowsze informacje... >>> http://link.interia.pl/f18f7
_______________________________________________
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/20060131/60615e07/attachment.html


More information about the Insight-users mailing list