[Insight-users] Problem showing Dicom Image : where is the error?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Insight-users] Problem showing Dicom Image : where is the error?

charfeddine amir
hi All
I'm developping an application that reads the first serie of
Dicom images from a directory, show each image and save it
in bmp format.
the problem is that image series is well readed, and image
are well saved in bmp format, but image are not well showed
in the vtkrenderwindow used ( i get a black window with two
white line on it and not the image readed).
this code in the main file :

this function is for reading first series from a given
directory and showing it's first dicom image(invoked by
pushing the Read Directory button in the GUI)
void
migAppBase
::ReadImage()
{
// Can only read an image once
if(m_InputImage.IsNotNull())
return;

char* chooserName = fl_dir_chooser("select a dicom directory", 0, 0);

// Store the filename
strcpy( m_InputImageDirectoryname, chooserName );
reader = ReaderType::New();
dicomIO = ImageIOType::New();
nameGenerator = NamesGeneratorType::New();
reader->SetImageIO( dicomIO );
nameGenerator->SetUseSeriesDetails( true );
nameGenerator->SetDirectory( m_InputImageDirectoryname );
seriesUID = nameGenerator->GetSeriesUIDs();

seriesIdentifier = seriesUID.begin()->c_str();

fileNames = nameGenerator->GetFileNames( seriesIdentifier );

FileNamesItr = fileNames.begin ();
FileNamesEnd = fileNames.end();


rescaler = RescaleFilterType::New();
rescaler->SetOutputMinimum( 0 );
rescaler->SetOutputMaximum( 255 );
reader->SetFileName( FileNamesItr->c_str() );

try
{
rescaler->SetInput( reader->GetOutput() );
reader->Update();
m_InputImage = reader->GetOutput();
m_InputImage->SetRequestedRegionToLargestPossibleRegion();

// Create the input image VTK pipeline
this->CreateInputImageWindow();

}
catch (itk::ExceptionObject &ex)
{
}

FileNamesItr++;
}

this function is for reading the next image in the serie
(invoked by pushing the Read Next button in the GUI)

void
migAppBase
::ReadNext()
{


if ( FileNamesItr != FileNamesEnd )
{

reader->SetFileName( FileNamesItr->c_str() );

try
{
rescaler->SetInput( reader->GetOutput() );
m_InputImage = reader->GetOutput();
m_InputImage->SetRequestedRegionToLargestPossibleRegion();
reader->Update();
// Create the input image VTK pipeline
this->CreateInputImageWindow();

}
catch (itk::ExceptionObject &ex)
{
}
FileNamesItr++;
}
}

this function is for saving the actual image (that should
be showed in the vtk window) in bmp format (invoked by
pushing the save Image in the GUI)

void
migAppBase
::SaveImage()
{

Writer2Type::Pointer writer2 = Writer2Type::New();

std::string OutputFilename1 = FileNamesItr->c_str() + std::string(".bmp");
writer2->SetFileName( OutputFilename1.c_str() );
writer2->SetInput( rescaler->GetOutput() );

try
{
writer2->Update();
}
catch (itk::ExceptionObject & e)
{
}

}

this is the fuction for showing the actual image

void
migAppBase
::CreateInputImageWindow()
{
// If this is the first time we've hit Image Suivante there's other stuff
// that needs to happen
if(m_IsFirstUpdate)
{
// Display the output image
CreateWindowWithRWI(m_InputInteractor, m_InputWindow, "Input Image");

// these two steps are VERY IMPORTANT, you have to show() the fltk window
// containing the vtkFlRenderWindowInteractor, and then the
// vtkFlRenderWindowInteractor itself
m_InputWindow->show();
m_InputInteractor->show();

// now we get to setup our VTK rendering pipeline
CreateInputImageVTKPipeline(m_InputInteractor);

// No longer the first update
m_IsFirstUpdate = false;
}
else
{
// Refresh the output window if not the first update
// NB: doing this on the first update on Windows causes a new
// renderwindow to spawn (not sure why)
m_InputRenderWindow->Render();
}

}

function(s) for fltk and vtk interaction( creation of the
vtkrenderwindow and integrating it to the fltk window)

void
migAppBase
::CreateWindowWithRWI(vtkFlRenderWindowInteractor *&flrwi, Fl_Window *&flw, char *title)
{
// set up main FLTK window
flw = new Fl_Window(300,330,title);

// and instantiate vtkFlRenderWindowInteractor (here it acts like a
// FLTK window, i.e. you could also instantiate it as child of a
// Fl_Group in a window)
flrwi = new vtkFlRenderWindowInteractor(5,5,290,260,NULL);

// this will result in a little message under the rendering
Fl_Box* box = new Fl_Box(5,261,290,34,
"3 = stereo, j = joystick, t = trackball, "
"w = wireframe, s = surface, p = pick; "
"you can also resize the window");
box->labelsize(10);
box->align(FL_ALIGN_WRAP);

// we're done populating the flw
flw->end();

// if the main window gets resized, the vtk window should resize with it
flw->resizable(flrwi);
}

void
migAppBase
::CreateInputImageVTKPipeline(vtkFlRenderWindowInteractor *flrwi)
{
// Abort if the user is being stupid
if(m_InputImage.IsNull())
return;

// create a rendering window and renderer
m_InputRenderer = vtkRenderer::New();
m_InputRenderer->SetBackground(0.0, 0.0, 0.0);

m_InputRenderWindow = vtkRenderWindow::New();
m_InputRenderWindow->AddRenderer(m_InputRenderer);

// NB: here we treat the vtkFlRenderWindowInteractor just like any other
// old vtkRenderWindowInteractor
flrwi->SetRenderWindow(m_InputRenderWindow);

// Hook the VTK pipeline up to the ITK pipeline
m_InputImageITKtoVTKexporter = itk::VTKImageExport<InputImageType>::New();
m_InputImageVTKimporter = vtkImageImport::New();
m_InputImageITKtoVTKexporter->SetInput( m_InputImage );
ConnectPipelines(m_InputImageITKtoVTKexporter, m_InputImageVTKimporter);

// Need to update prior to creating the cutting planes
m_InputImageITKtoVTKexporter->Update();
m_InputImageVTKimporter->Update();

// Create the image cutting planes
m_InputImagePlaneX = vtkImagePlaneWidget::New();
m_InputImagePlaneX->RestrictPlaneToVolumeOn();
m_InputImagePlaneX->SetResliceInterpolateToCubic();
m_InputImagePlaneX->SetInput( (vtkDataSet*) m_InputImageVTKimporter->GetOutput() );
m_InputImagePlaneX->SetPlaneOrientationToXAxes();
m_InputImagePlaneX->SetSliceIndex( 0 );

m_InputImagePlaneY = vtkImagePlaneWidget::New();
m_InputImagePlaneY->RestrictPlaneToVolumeOn();
m_InputImagePlaneY->SetResliceInterpolateToCubic();
m_InputImagePlaneY->SetInput( (vtkDataSet*) m_InputImageVTKimporter->GetOutput() );
m_InputImagePlaneY->SetPlaneOrientationToYAxes();
m_InputImagePlaneY->SetSliceIndex( 0 );
// Set the position of the image planes to the center of the volume
this->ResetInputImagePlaneWidgets();

// Link the image planes to the interactor
m_InputImagePlaneX->SetInteractor( flrwi );
m_InputImagePlaneY->SetInteractor( flrwi );

// Turn on the image plane so they display
m_InputImagePlaneX->On();
m_InputImagePlaneY->On();

// just like with any other vtkRenderWindowInteractor(), you HAVE to call
// Initialize() before the interactor will function. See the docs in
// vtkRenderWindowInteractor.h
// This must occur AFTER the image planes have been added to the interactor
flrwi->Initialize();

// Clean up memory allocation (NB: not actually deleted until program returns)
m_InputRenderer->Delete();
m_InputRenderWindow->Delete();
}

thx for help
any comment is welcome
Amir


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.
_______________________________________________
Insight-users mailing list
[hidden email]
http://www.itk.org/mailman/listinfo/insight-users
Reply | Threaded
Open this post in threaded view
|

Re: [Insight-users] Problem showing Dicom Image : where is the error?

Luis Ibanez

Hi Amir,

What PixelType are you using ?

It is a common mistake to use "unsigned short" (or 16 bits)
as pixel type, and store on it only 8-bits. Like the rescaling
that you are doing from 0 to 255.

When you do this, and visualize the image, the information
may be there but due to the large dynamic range of  16 bits,
your pixels will appear completely dark.

In other words, with a 16bits image you have a range of

           0   to   65535

so, if you store pixel with values from 0 to 255, those
pixels will appear very very dark.


You can verify this by simply loading your BMP files in
a viewer that allows you to do normalization of the image.

For example:


        - GIMP
        - display (from ImageMagick)


Please do not use the default viewers that you find in
Windows. They are not intended for being used in medical
images, and are therefore a risk for public health.


Let us know what you find.



    Thanks


      Luis



--------------------------
charfeddine amir wrote:

>
>
> hi All
> I'm developping an application that reads the first serie of
> Dicom images from a directory, show each image and save it
> in bmp format.
> the problem is that image series is well readed, and image
>   are well saved in bmp format, but image are not well showed
> in the vtkrenderwindow used ( i get a black window with two
> white line on it and not the image readed).
> this code in the main file :
>
> this function is for reading first series from a given  
> directory and showing it's first dicom image(invoked by
> pushing the Read Directory button in the GUI)
> void
> migAppBase
> ::ReadImage()
> {
>   // Can only read an image once
>   if(m_InputImage.IsNotNull())  
>    return;
>  
>   char* chooserName = fl_dir_chooser("select a dicom directory", 0, 0);
>
>   // Store the filename
>   strcpy( m_InputImageDirectoryname, chooserName );
>   reader = ReaderType::New();  
>   dicomIO =
>  ImageIOType::New();
>   nameGenerator = NamesGeneratorType::New();
>   reader->SetImageIO( dicomIO );
>   nameGenerator->SetUseSeriesDetails( true );
>   nameGenerator->SetDirectory( m_InputImageDirectoryname );  
>   seriesUID = nameGenerator->GetSeriesUIDs();
>    
>   seriesIdentifier = seriesUID.begin()->c_str();
>      
>   fileNames = nameGenerator->GetFileNames( seriesIdentifier );
>
>   FileNamesItr = fileNames.begin  ();
>   FileNamesEnd = fileNames.end();
>    
>    
>   rescaler = RescaleFilterType::New();
>   rescaler->SetOutputMinimum(   0 );
>   rescaler->SetOutputMaximum( 255 );
>   reader->SetFileName( FileNamesItr->c_str() );  
>
>   try
>       {
>     rescaler->SetInput( reader->GetOutput() );
>     reader->Update();
>     m_InputImage = reader->GetOutput();
>     m_InputImage->SetRequestedRegionToLargestPossibleRegion();  
>    
>     // Create the input image VTK pipeline
>  !
>    
>  this->CreateInputImageWindow();
>
>   }
>     catch (itk::ExceptionObject &ex)
>       {
>       }
>
>   FileNamesItr++;
> }
>
> this function is for reading the next image in the serie  
> (invoked by pushing the Read Next button in the GUI)
>
>  void
> migAppBase
> ::ReadNext()
> {
>
>
> if ( FileNamesItr != FileNamesEnd )
> {
>
> reader->SetFileName( FileNamesItr->c_str() );
>
>     try
>       {
>     rescaler->SetInput( reader->GetOutput() );
>     m_InputImage = reader->GetOutput();
>     m_InputImage->SetRequestedRegionToLargestPossibleRegion();
>     reader->Update();
>     // Create the input image VTK pipeline  
>     this->CreateInputImageWindow();
>
>       }
>     catch (itk::ExceptionObject &ex)
>       {
>       }
> FileNamesItr++;
> }
> }
>
> this function is for saving the actual image (that should
>   be showed in the vtk window) in bmp format (invoked by
> pushing the!
>   save
>  Image in the GUI)
>
>  void
> migAppBase
> ::SaveImage()
> {
>
> Writer2Type::Pointer writer2 = Writer2Type::New();
>
> std::string OutputFilename1 = FileNamesItr->c_str() + std::string(".bmp");  
> writer2->SetFileName( OutputFilename1.c_str() );
> writer2->SetInput( rescaler->GetOutput() );
>
>   try
>     {
>     writer2->Update();
>     }
>   catch (itk::ExceptionObject & e)
>     {
>       }
>
> }
>
> this is the fuction for showing the actual image
>
> void
> migAppBase
> ::CreateInputImageWindow()
> {
>   // If this is the first time we've hit Image Suivante there's other stuff
>   // that needs to happen  
>   if(m_IsFirstUpdate)
>   {
>     // Display the output image
>     CreateWindowWithRWI(m_InputInteractor, m_InputWindow, "Input Image");
>
>   // these two steps are VERY IMPORTANT, you have to show() the fltk window  
>   // containing the vtkFlRenderWindowInteractor, and then the
>   //
>  vtkFlRenderWindowInteractor itself
>   m_InputWindow->show();
>   m_InputInteractor->show();
>    
>   // now we get to setup our VTK rendering pipeline  
>   CreateInputImageVTKPipeline(m_InputInteractor);
>
>     // No longer the first update
>     m_IsFirstUpdate = false;
>   }
>   else
>   {
>     // Refresh the output window if not the first update
>     // NB: doing this on the first update on Windows causes a new  
>     // renderwindow to spawn (not sure why)
>    m_InputRenderWindow->Render();
>   }
>  
> }
>
> function(s) for fltk and vtk interaction( creation of the
> vtkrenderwindow and integrating it to the fltk window)  
>
> void
> migAppBase
> ::CreateWindowWithRWI(vtkFlRenderWindowInteractor *&flrwi, Fl_Window *&flw, char *title)
> {
>    // set up main FLTK window
>    flw = new Fl_Window(300,330,title);
>    
>    // and instantiate vtkFlRenderWindowInteractor (here it acts like a  
>    // FLTK window, !
>  i.e. you
>  could also instantiate it as child of a
>    // Fl_Group in a window)
>    flrwi = new vtkFlRenderWindowInteractor(5,5,290,260,NULL);
>
>    // this will result in a little message under the rendering  
>    Fl_Box* box = new Fl_Box(5,261,290,34,
>                              "3 = stereo, j = joystick, t = trackball, "
>                             "w = wireframe, s = surface, p = pick; "
>                             "you can also resize the window");  
>    box->labelsize(10);
>    box->align(FL_ALIGN_WRAP);
>    
>    // we're done populating the flw
>    flw->end();
>
>    // if the main window gets resized, the vtk window should resize with it
>    flw->resizable(flrwi);  
> }
>
> void
> migAppBase
> ::CreateInputImageVTKPipeline(vtkFlRenderWindowInteractor *flrwi)
> {
>   // Abort if the user is being stupid
>   if(m_InputImage.IsNull())
>     return;
>
>   // create a rendering window and renderer  
>   m_InputRenderer =
>  vtkRenderer::New();
>   m_InputRenderer->SetBackground(0.0, 0.0, 0.0);
>  
>   m_InputRenderWindow = vtkRenderWindow::New();
>   m_InputRenderWindow->AddRenderer(m_InputRenderer);
>      
>   // NB: here we treat the vtkFlRenderWindowInteractor just like any other
>   // old vtkRenderWindowInteractor
>   flrwi->SetRenderWindow(m_InputRenderWindow);
>
>   // Hook the VTK pipeline up to the ITK pipeline  
>   m_InputImageITKtoVTKexporter = itk::VTKImageExport<InputImageType>::New();
>   m_InputImageVTKimporter = vtkImageImport::New();
>   m_InputImageITKtoVTKexporter->SetInput( m_InputImage );
>   ConnectPipelines(m_InputImageITKtoVTKexporter, m_InputImageVTKimporter);  
>
>   // Need to update prior to creating the cutting planes
>   m_InputImageITKtoVTKexporter->Update();
>   m_InputImageVTKimporter->Update();
>
>   // Create the image cutting planes
>   m_InputImagePlaneX = vtkImagePlaneWidget::New();  
>  
>  m_InputImagePlaneX->RestrictPlaneToVolumeOn();
>   m_InputImagePlaneX->SetResliceInterpolateToCubic();
>   m_InputImagePlaneX->SetInput( (vtkDataSet*) m_InputImageVTKimporter->GetOutput() );
>   m_InputImagePlaneX->SetPlaneOrientationToXAxes();  
>   m_InputImagePlaneX->SetSliceIndex( 0 );
>  
>   m_InputImagePlaneY = vtkImagePlaneWidget::New();
>   m_InputImagePlaneY->RestrictPlaneToVolumeOn();
>   m_InputImagePlaneY->SetResliceInterpolateToCubic();  
>   m_InputImagePlaneY->SetInput( (vtkDataSet*) m_InputImageVTKimporter->GetOutput() );
>   m_InputImagePlaneY->SetPlaneOrientationToYAxes();
>   m_InputImagePlaneY->SetSliceIndex( 0 );
>   // Set the position of the image planes to the center of the volume  
>   this->ResetInputImagePlaneWidgets();
>
>   // Link the image planes to the interactor
>   m_InputImagePlaneX->SetInteractor( flrwi );
>   m_InputImagePlaneY->SetInteractor( flrwi );
>
>   // Turn on t!
>  he image
>  plane so they display  
>   m_InputImagePlaneX->On();
>   m_InputImagePlaneY->On();
>
>   // just like with any other vtkRenderWindowInteractor(), you HAVE to call
>   // Initialize() before the interactor will function.  See the docs in  
>   // vtkRenderWindowInteractor.h
>   // This must occur AFTER the image planes have been added to the interactor
>   flrwi->Initialize();
>
>   // Clean up memory allocation (NB: not actually deleted until program returns)  
>   m_InputRenderer->Delete();
>   m_InputRenderWindow->Delete();
> }
>
> thx for help
> any comment is welcome
> Amir
>
> ------------------------------------------------------------------------
> Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les
> tarifs exceptionnels pour appeler la France et l'international.
> Téléchargez
> <http://us.rd.yahoo.com/messenger/mail_taglines/default/*http://fr.beta.messenger.yahoo.com>
> la version beta.
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> [hidden email]
> http://www.itk.org/mailman/listinfo/insight-users

_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers