[Insight-users] problem in rescaling while using itkMinimumMaximumImageCalculator
john smith
mkitkinsightuser at gmail.com
Tue Jun 7 05:57:40 EDT 2011
Hello to all,
I am using an itkExtractImageFilter, an itkRescaleIntensityImageFilter and
an itkMinimumMaximumImageCalculator.With my code I want to read a 3D volume,
get a 2D slice, rescale it and then diplay this slice. But If the maximum
pixel value of the image is up to 255, then I want to rescale between
[0,255]. But if the maximum pixel value(value_max) is less than 255 then I
want to rescale my image between [0,value_max].I am using the 3D image
(MRI-crop-original.gipl, itk-snap's free data) as input and I am extracting
the first slice. This slice has value_max=122, so I should rescale it
between [0,value_max]. But when I am running my program I get the result
image (z.png) rescaled between [0,255].
I think that my problem is that when using the
itkMinimumMaximumImageCalculator, I do not get tthe right values
[value_min,value_max]=[0,122], but I am taking these values
[value_min,value_max]=[255,0] and I think that there must be some mistake.
Also, I think that the itkExtractImageFilter, make the rescale of my image
between [0,255].Is this right? I hope somebody could help
Thanks in advance
typedef unsigned char InputPixelType;
typedef unsigned char OutputPixelType;
typedef itk::Image< InputPixelType, 3 > InputImageType;
typedef itk::Image< OutputPixelType, 2 > OutputImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
typedef itk::ExtractImageFilter< InputImageType, OutputImageType >
FilterType;
FilterType::Pointer filter = FilterType::New();
typedef itk::RescaleIntensityImageFilter< OutputImageType,
OutputImageType > FilterType_rescale;
typedef itk::MinimumMaximumImageCalculator <OutputImageType>
ImageCalculatorFilterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( fileName.toStdString() );
writer->SetFileName( "z.png" );
reader->Update();
InputImageType::RegionType inputRegion =
reader->GetOutput()->GetLargestPossibleRegion();
InputImageType::SizeType size = inputRegion.GetSize();
size[2] = 0;
InputImageType::IndexType start = inputRegion.GetIndex();
ui->verticalScrollBar_z->setRange(1,size_z);
unsigned int sliceNumber = ui->verticalScrollBar_z->value();
start[2] = 0;
InputImageType::RegionType desiredRegion;
desiredRegion.SetSize( size );
desiredRegion.SetIndex( start );
filter->SetExtractionRegion( desiredRegion );
filter->SetInput( reader->GetOutput() );
filter->Update();
ImageCalculatorFilterType::Pointer imageCalculatorFilter
= ImageCalculatorFilterType::New ();
imageCalculatorFilter->SetImage(filter->GetOutput());
int value_max = imageCalculatorFilter->GetMaximum();
int value_min = imageCalculatorFilter->GetMinimum();
ui->label_20->setText(QString("max_value:%1").arg(value_max));
ui->label_21->setText(QString("min_value:%1").arg(value_min));
FilterType_rescale::Pointer filter_rescale = FilterType_rescale::New();
filter_rescale->SetOutputMinimum( 0 );
filter_rescale->SetOutputMaximum( value_max);
filter_rescale->SetInput( filter->GetOutput() );
writer->SetInput( filter_rescale->GetOutput() );
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110607/c99e5d23/attachment.htm>
More information about the Insight-users
mailing list