[Insight-users] ExtractImageFilter for vector field
Sadegh
sadegh.riyahi at gmail.com
Mon Jul 29 14:12:54 EDT 2013
Hello Brad!
Sorry, I faced another problem this time which is the compile error.
Actually the previous code had an conceptual error, which must be changed to
the following:
//////////////////////
const unsigned int InputImageDimension =3;
const unsigned int FrameDimension =2;
typedef float InputPixelType3D;
typedef itk::Image< InputPixelType3D, InputImageDimension >
InputImageType3D;
typedef itk::Image< InputPixelType3D, FrameDimension > FixedImageType;
FixedImageType::Pointer fixedimage = FixedImageType::New();
typedef itk::Vector< InputPixelType3D, InputImageDimension >
VectorPixelType;
typedef itk::Image< VectorPixelType, InputImageDimension >
InputDeformationFieldType;
typedef itk::ImageFileReader< InputDeformationFieldType >
DeformationFieldReaderType;
typedef itk::Vector< float, FrameDimension > VectorPixelType2D;
typedef itk::Image< VectorPixelType2D, FrameDimension >
FrameDeformationFieldType;
FrameDeformationFieldType::Pointer vectorimage =
FrameDeformationFieldType::New();
typedef itk::ExtractImageFilter< InputDeformationFieldType,
FrameDeformationFieldType> InputFilterType2D;
////////////////
FrameDeformationFieldType::Pointer
extract2DImageSlice(InputDeformationFieldType::Pointer reader, int plane,
int slice) {
reader->UpdateOutputInformation();
InputFilterType2D::Pointer filter = InputFilterType2D::New();
filter->InPlaceOn();
filter->SetDirectionCollapseToSubmatrix();
//filter->SetDirectionCollapseToIdentity();
InputDeformationFieldType::RegionType inputRegion =
reader->GetRequestedRegion();
InputDeformationFieldType::SizeType size = inputRegion.GetSize();
size[plane] = 1;
InputDeformationFieldType::IndexType start = inputRegion.GetIndex();
const unsigned int sliceNumber = slice;
start[plane] = sliceNumber;
InputDeformationFieldType::RegionType desiredRegion;
desiredRegion.SetSize( size );
desiredRegion.SetIndex( start );
filter->SetExtractionRegion( desiredRegion );
filter->SetInput( reader );
FrameDeformationFieldType::Pointer img = filter->GetOutput();
img->Update();
return img;
}
/////////////////////////////////////////
So the main change is that ExtractImageFilter< InputDeformationFieldType,
FrameDeformationFieldType> receives a 3D vector field as input
(InputDeformationFieldType) and gives back 2D vector field
(FrameDeformationFieldType) as output. so the function extract2DImageSlice
will do the same.
now I receive the following error :
*error C2440: 'static_cast' : cannot convert from
'itk::Vector<T,NVectorDimension>' to 'itk::Vector<T,NVectorDimension>'
d:\phd-project\open-source\insighttoolkit-4.1.0\modules\core\common\include\itkConceptChecking.h
185*
It might be from the other parts of the code which calculates the jacobian
determinant which I post it below:
/////////////////BEGIN///////////////
typedef
itk::DisplacementFieldJacobianDeterminantFilter<FrameDeformationFieldType,
float> JacobianFilterType;
DeformationFieldReaderType::Pointer fieldReader =
DeformationFieldReaderType::New();
typedef itk::Image<float,2> ImageType;
fieldReader->SetFileName( argv[1] );
std::cout << "1";
// Update the reader
try
{
fieldReader->Update();
}
catch( itk::ExceptionObject& err )
{
std::cout << "Could not read the input field." << std::endl;
std::cout << err << std::endl;
exit( EXIT_FAILURE );
}
//inputVelField = fieldReader->GetOutput();
InputDeformationFieldType::Pointer deffield;
deffield=fieldReader->GetOutput();
//sprintf(filename,"realvalues/deffield%d.mha",this->GetElapsedIterations());
unsigned int Component = 2;
unsigned int numberOfFrames = 476;
if( argc > 2 )
numberOfFrames= atoi(argv[2]) ;
std::cout << "1";
std::ofstream parametersFile;
std::ostringstream ostr;
ostr.str("");
ostr<<argv[3];
parametersFile.open( ostr.str());
typedef itk::ImageRegionIterator< ImageType > IteratorType;
for (int j=1; j <= numberOfFrames; j++)
{
try
{
vectorimage = extract2DImageSlice(deffield, Component, j);
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_SUCCESS;
}
JacobianFilterType::Pointer jacobianFilter = JacobianFilterType::New();
jacobianFilter->SetInput( vectorimage );
jacobianFilter->SetUseImageSpacing( true );
IteratorType it( jacobianFilter->GetOutput(),
jacobianFilter->GetOutput()->GetRequestedRegion() );
int shrink, nochange, increase ;
shrink = nochange =increase =0;
int i =0;
it.Begin();
while( !it.IsAtEnd() )
{
if (it.Get() < 1)
shrink++;
else if (it.Get() == 1)
nochange++;
else increase++;
++it;i++;
}
float shrinkpercent = (float)((shrink*100)/i);
float nopercent = (float)((nochange*100)/i);
float incpercent = (float)((increase*100)/i);
typedef itk::MinimumMaximumImageCalculator<ImageType> MinMaxFilterType;
MinMaxFilterType::Pointer minmaxfilter = MinMaxFilterType::New();
minmaxfilter->SetImage( jacobianFilter->GetOutput() );
minmaxfilter->Compute();
std::cout << "Writing "<<j<<"th frame Jacobian result
parameter ...";
parametersFile << "Frame No: " <<j<<std::endl;
parametersFile << "Max number of Pixels: "
<<i<<std::endl;
parametersFile << "Number of pixels Jac < 1: "
<<shrink<<",
--Percentage:"<<shrinkpercent<<"%"<<std::endl;
parametersFile << "Number of pixels Jac > 1:
"<<increase<<",
--Percentage:"<<incpercent<<"%"<<std::endl;
parametersFile << "Number of pixels Jac = 1:
"<<nochange<<",
--Percentage:"<<nopercent<<"%"<<std::endl;
parametersFile<<"Minimum of the determinant of the Jacobian of
the warp: "
<<minmaxfilter->GetMinimum()<<std::endl;
parametersFile<<"Maximum of the determinant of the Jacobian
of the warp: "
<<minmaxfilter->GetMaximum()<<std::endl;
parametersFile<<"-------------------------------------------------------------"<<std::endl;
}
parametersFile.close();
return EXIT_SUCCESS;
}
/////////////////END///////////////
Now the concept of what I want to DO should be okay logically. But I do not
understand the meaning of the error and why it comes..
Thanks and sorry again.
-----
Sadegh Riyahi
Politecnico di Milano
--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/ExtractImageFilter-for-vector-field-tp7583612p7583623.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list