[vtkusers] Rescaling vtkWindowToImageFilter output

Sercani Sercani sercanimailgroups at gmail.com
Mon Dec 26 09:54:43 EST 2011


Hi everyone;
I need to create a DICOM image from vtkRenderWindow contents and send it to
a DICOM printer.
I used vtkWindowToImageFilter to get the screenshot of the render window,
at first i casted it to monochrome image using vtkImageLuminance, and
converted the scalar type to unsigned short using vtkImageCast. The reason
of this conversions is; vtkWindowToImageFilter creates RGB images which
uses char as scalar type and vtkGDCMImageWriter doesn't accept the unsigned
char as an input. I gave the output of the last filter to
vtkGDCMImageWriter but the result is a little bit paler than the original
DICOM file(but if i change the window / level values it just looks like the
original image). I think the reason of this "paleness" is the difference of
the scalar ranges of original DICOM image(which is -1000 and +2000 after
rescaling) and the exported RGB screenshot(0-255)...So i need to rescale
the image and define suitable values for window / level. I tried to give
the original image's values but no difference, i didn't set any values and
let the vtkGDCMImageWriter to determine them, still no good results. What
should be the shift and scale values for rescaling the output of the
vtkWindowToImageFilter? Any help will be appreciated,thanks already....

this->Image->SetImageItem(tempitem);//set the current imagedata to the
vtkImageSlice
this->Image->GetRenderWindow()->OffScreenRenderingOn();
this->Image->SetCameraPositions(activeFrame->GetActiveCamera());
this->Image->RenderFrame();

vtkWindowToImageFilter *windowToImage = vtkWindowToImageFilter::New();
windowToImage->SetInput(this->Image->GetRenderWindow());

vtkImageLuminance *luminance = vtkImageLuminance::New();
luminance->SetInputConnection(windowToImage->GetOutputPort());

vtkImageCast *cast = vtkImageCast::New();
cast->SetInputConnection(luminance->GetOutputPort());
cast->SetOutputScalarTypeToUnsignedShort();

vtkGDCMImageWriter *dicomExport = vtkGDCMImageWriter::New();
dicomExport->SetFileName(filename.toStdString().c_str());
dicomExport->SetInput(cast->GetOutput());
dicomExport->SetImageFormat(0);
dicomExport->SetMedicalImageProperties(tempitem->GetImageProperties());
dicomExport->SetShift(tempitem->GetShift());
dicomExport->SetScale(tempitem->GetScale());
dicomExport->Write();

this->Image->GetRenderWindow()->OffScreenRenderingOff();
cast->Delete();
luminance->Delete();
windowToImage->Delete();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111226/08d4c1fa/attachment.htm>


More information about the vtkusers mailing list