Hello to all,<br><br>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].<br><div id=":1hf">
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.<br>
Also, I think that the itkExtractImageFilter, make the rescale of my
image between [0,255].Is this right? I hope somebody could help<br>Thanks in advance<br><br> typedef unsigned char InputPixelType;<br>typedef unsigned char OutputPixelType;<br>
typedef itk::Image< InputPixelType, 3 > InputImageType;<br>typedef itk::Image< OutputPixelType, 2 > OutputImageType;<br><br>typedef itk::ImageFileReader< InputImageType > ReaderType;<br>typedef itk::ImageFileWriter< OutputImageType > WriterType;<br>
<br>typedef itk::ExtractImageFilter< InputImageType, OutputImageType > FilterType;<br> FilterType::Pointer filter = FilterType::New();<br><br> typedef itk::RescaleIntensityImageFilter< OutputImageType, <br>OutputImageType > FilterType_rescale;<br>
<br> typedef itk::MinimumMaximumImageCalculator <OutputImageType><br> ImageCalculatorFilterType;<br><br><br> ReaderType::Pointer reader = ReaderType::New();<br> WriterType::Pointer writer = WriterType::New();<br>
<br> reader->SetFileName( fileName.toStdString() );<br> writer->SetFileName( "z.png" );<br><br> reader->Update();<br> InputImageType::RegionType inputRegion =<br> reader->GetOutput()->GetLargestPossibleRegion();<br>
<br> InputImageType::SizeType size = inputRegion.GetSize();<br> size[2] = 0;<br><br> InputImageType::IndexType start = inputRegion.GetIndex();<br> ui->verticalScrollBar_z->setRange(1,size_z);<br> unsigned int sliceNumber = ui->verticalScrollBar_z->value();<br>
start[2] = 0;<br><br> InputImageType::RegionType desiredRegion;<br> desiredRegion.SetSize( size );<br> desiredRegion.SetIndex( start );<br><br> filter->SetExtractionRegion( desiredRegion );<br><br> filter->SetInput( reader->GetOutput() );<br>
filter->Update();<br><br> ImageCalculatorFilterType::Pointer imageCalculatorFilter<br> = ImageCalculatorFilterType::New ();<br> imageCalculatorFilter->SetImage(filter->GetOutput());<br><br><br> int value_max = imageCalculatorFilter->GetMaximum();<br>
int value_min = imageCalculatorFilter->GetMinimum();<br><br> ui->label_20->setText(QString("max_value:%1").arg(value_max));<br> ui->label_21->setText(QString("min_value:%1").arg(value_min));<br>
<br> <br> FilterType_rescale::Pointer filter_rescale = FilterType_rescale::New();<br> filter_rescale->SetOutputMinimum( 0 );<br> filter_rescale->SetOutputMaximum( value_max);<br> <br><br> filter_rescale->SetInput( filter->GetOutput() );<br>
writer->SetInput( filter_rescale->GetOutput() );</div>