[Insight-users] How GetPixel value

mariusz_smch at poczta.fm mariusz_smch at poczta.fm
Tue Jan 31 02:10:26 EST 2006


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 : "<<pixel_value<<endl; 
(...)

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
-------------- next part --------------
_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list