[Insight-users] How GetPixel value
mariusz_smch at poczta.fm
mariusz_smch at poczta.fm
Mon Jan 30 02:39:21 EST 2006
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<vtkRenderer*>(caller);
//vtkRenderWindowInteractor* renderWindowInteractor=reinterpret_cast<vtkRenderWindowInteractor*>(caller);
//vtkImageViewer* viewer=reinterpret_cast<vtkImageViewer*>(caller);
int x,y;
renderWindowInteractor->GetEventPosition (x, y);
float level=viewer->GetColorLevel();
cout<<"Level: "<<level<<" ";
float color_window=viewer->GetColorWindow();
cout<<"ColorWindow: "<<color_window<<" ";
cout<<" x: "<<x<<" y: "<<y;//<<endl;
typedef itk::Image<signed short, 2 > InputImageType;
InputImageType::IndexType index;
index[0]=x;
index[1]=y;
cout<<" Index x: "<<index[0]<<" y: "<<index[1];
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<InputImageType> 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:"<<level<<endl;
std::cerr<<"Color window:"<<color_window<<endl;
renderWindowInteractor->Disable
renderWindowInteractor->Delete();
viewer->Delete();
};
Thanks for help
Mariusz.
----------------------------------------------------------------------
Najwiekszy czat w Polsce!!! >>> http://link.interia.pl/f18f6
More information about the Insight-users
mailing list