<div dir="ltr">Hi Massinissa,<div><br></div><div>You  are mixing two concepts in your code.</div><div><br></div><div>They are</div><div> </div><div>             A) The PixelType of an itk::Image. As in itk::Image<PixelType,3> </div>
<div><br></div><div>                          and</div><div><br></div><div>              B) The IOComponentType of an ImageIO class, as defined in:</div><div><a href="https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/ImageBase/include/itkImageIOBase.h#L106">https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/ImageBase/include/itkImageIOBase.h#L106</a><br>
</div><div><br></div><div><br></div><div><br></div><div>The type (A) is expected to be : char, int, short, float, double,.... or a vector type.</div><div><br></div><div>The type (B) is actually an enum, and therefore, closely equivalent to an int.</div>
<div><br></div><div><br></div><div>What the compilation error is indicating is that:</div><div><br></div><div><br></div><div>                        You can't use (B) as an option for (A).</div><div><br></div><div><br>
</div><div><br></div><div><br></div><div>The code that you need, should have the pseudo code structure:</div><div><br></div><div><br></div><div>GET_IOCOMPONENT_TYPE</div><div><br></div><div>switch( IOTYPE )</div><div>{</div>
<div>case UCHAR:</div><div>    typedef  proper ImagePixelType</div><div>    declare registration type with this type<br><div>case CHAR:</div><div>    typedef  proper ImagePixelType</div><div>    declare registration type with this type<br>
</div></div><div><div>case INT:</div><div>    typedef  proper ImagePixelType</div><div>    declare registration type with this type<br></div></div><div>....</div><div>etc</div><div>}</div><div><br></div><div><br></div><div>
More explicitly it should be:</div><div><br></div><div><br></div><div><div>class TomoRegistration : public QMainWindow, Ui::TomoRegistrationClass</div><div>{</div><div>public:</div><div>void test(){</div><div><br></div><div>
        typedef itk::ImageIOBase::IOComponentType ScalarPixelType;</div><div><br></div><div>        itk::ImageIOBase::Pointer imageIOsource = itk::ImageIOFactory::CreateImageIO("writesource.mhd",itk::ImageIOFactory::ReadMode);</div>
<div><br></div><div>        imageIOsource->SetFileName("writesource.mhd");</div><div>        imageIOsource->ReadImageInformation();</div><div><br></div><div>        itk::ImageIOBase::Pointer imageIOtarget = itk::ImageIOFactory::CreateImageIO("writetarget.mhd",itk::ImageIOFactory::ReadMode);</div>
<div>        imageIOtarget->SetFileName("writetarget.mhd");</div><div>        imageIOtarget->ReadImageInformation();</div><div><br></div><div>        ITKRegistration *MI;  // ... etc</div><div>        int iteration = 100;</div>
<div><br></div><div>        const itk::ImageIOBase::IOComponentType pixelTypeSource = imageIOsource->GetComponentType();</div><div>        const itk::ImageIOBase::IOComponentType pixelTypeTarget = imageIOtarget->GetComponentType();</div>
<div><br></div><div>        switch( pixelTypeSource )</div><div>        {</div><div>        case itk::ImageIOBase::UCHAR:</div><div>          {</div><div>          typedef unsigned char SourcePixelType;</div><div>          SourcePixelType spt;</div>
<div>          switch( pixelTypeTarget )</div><div>          {</div><div>          case itk::ImageIOBase::UCHAR:</div><div>            {</div><div>            typedef unsigned char TargetPixelType;</div><div>            TargetPixelType tpt;</div>
<div>            MI->VolumeRegistration("writesource.mhd","writetarget.mhd",iteration,spt,tpt);</div><div>            break;</div><div>            }</div><div>          case itk::ImageIOBase::CHAR:</div>
<div>            {</div><div>            typedef char TargetPixelType;</div><div>            TargetPixelType tpt;</div><div>            MI->VolumeRegistration("writesource.mhd","writetarget.mhd",iteration,spt,tpt);</div>
<div>            break;</div><div>            }</div><div>          case itk::ImageIOBase::FLOAT:</div><div>            {</div><div>            typedef float TargetPixelType;</div><div>            TargetPixelType tpt;</div>
<div>            MI->VolumeRegistration("writesource.mhd","writetarget.mhd",iteration,spt,tpt);</div><div>            break;</div><div>            }</div><div>          }</div><div>          break;</div>
<div>          }</div><div>        case itk::ImageIOBase::UINT:</div><div>          {</div><div>          typedef unsigned int SourcePixelType;</div><div>          SourcePixelType spt;</div><div>          switch( pixelTypeTarget )</div>
<div>          {</div><div>          case itk::ImageIOBase::UCHAR:</div><div>            {</div><div>            typedef unsigned char TargetPixelType;</div><div>            TargetPixelType tpt;</div><div>            MI->VolumeRegistration("writesource.mhd","writetarget.mhd",iteration,spt,tpt);</div>
<div>            break;</div><div>            }</div><div>          case itk::ImageIOBase::CHAR:</div><div>            {</div><div>            typedef char TargetPixelType;</div><div>            TargetPixelType tpt;</div>
<div>            MI->VolumeRegistration("writesource.mhd","writetarget.mhd",iteration,spt,tpt);</div><div>            break;</div><div>            }</div><div>          case itk::ImageIOBase::FLOAT:</div>
<div>            {</div><div>            typedef float TargetPixelType;</div><div>            TargetPixelType tpt;</div><div>            MI->VolumeRegistration("writesource.mhd","writetarget.mhd",iteration,spt,tpt);</div>
<div>            break;</div><div>            }</div><div>          }</div><div>          break;</div><div>          }</div><div>        }</div><div><br></div><div>}</div><div>};</div></div><div><br></div><div><br></div><div>
<br></div><div><br></div><div>Note that, for the sake of brevity, this code above doesn't have all the combinations of types.</div><div>You will have to extend the "case" statements in the "switch" to cover all the combinations</div>
<div>of pixels types that you are interested in processing.</div><div><br></div><div><br></div><div> </div><div>    Regards</div><div><br></div><div><br></div><div>        Luis</div><div><br></div><div><br></div><div><br>
</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 10, 2014 at 11:00 PM, Massinissa Bandou <span dir="ltr"><<a href="mailto:Massinissa.Bandou@usherbrooke.ca" target="_blank">Massinissa.Bandou@usherbrooke.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear ITK<br>
<br>
I'm trying to use a template function to read 2 unknown images type for a<br>
mutual information registration. The problem is in pixelType1 & pixelType2<br>
(specified in test() function of class TomoRegistration). If I replace them<br>
by float or double or any other format, the program compiles and works fine.<br>
In other hand, I get these errors:<br>
<br>
Error   2       error C2146: syntax error : missing ';' before identifier<br>
'ComponentType' c:\program<br>
files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h        45      1<br>
TomoRegistration<br>
Error   4       error C2602:<br>
'itk::DefaultConvertPixelTraits<PixelType>::ComponentType' is not a member<br>
of a base class of 'itk::DefaultConvertPixelTraits<PixelType>'  c:\program<br>
files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h        45      1<br>
TomoRegistration<br>
Error   1       error C2838: 'ComponentType' : illegal qualified name in member<br>
declaration     c:\program<br>
files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h        45      1<br>
TomoRegistration<br>
Error   5       error C2868:<br>
'itk::DefaultConvertPixelTraits<PixelType>::ComponentType' : illegal syntax<br>
for using-declaration; expected qualified-name  c:\program<br>
files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h        45      1<br>
TomoRegistration<br>
Error   3       error C4430: missing type specifier - int assumed. Note: C++ does<br>
not support default-int c:\program<br>
files\itk\include\itk-4.4\itkDefaultConvertPixelTraits.h        45      1<br>
TomoRegistration<br>
<br>
<br>
<br>
class ITKRegistration<br>
{<br>
public:<br>
        ITKRegistration();<br>
        ~ITKRegistration();<br>
<br>
template<typename pixelType1, typename pixelType2><br>
        vtkSmartPointer<vtkMatrix4x4> VolumeRegistration(const string source, const<br>
string target,int iteration,pixelType1,pixelType2)<br>
        {<br>
                typedef itk::Image< pixelType1, 3 >  FixedImageType;<br>
                typedef itk::Image< pixelType2, 3 >  MovingImageType;<br>
<br>
                typedef itk::VersorRigid3DTransform< double > TransformType;<br>
                typedef itk::VersorRigid3DTransformOptimizer<br>
OptimizerType;<br>
                //typedef itk::MeanSquaresImageToImageMetric< FixedImageType,<br>
MovingImageType > MetricType;<br>
                typedef itk::MutualInformationImageToImageMetric< FixedImageType,<br>
MovingImageType > MetricType;<br>
                typedef itk::LinearInterpolateImageFunction< MovingImageType, double ><br>
InterpolatorType;<br>
                typedef itk::ImageRegistrationMethod< FixedImageType, MovingImageType ><br>
RegistrationType;<br>
<br>
                MetricType::Pointer         metric        = MetricType::New();<br>
                OptimizerType::Pointer      optimizer     = OptimizerType::New();<br>
                InterpolatorType::Pointer   interpolator  = InterpolatorType::New();<br>
                TransformType::Pointer  transform = TransformType::New();<br>
<br>
                RegistrationType::Pointer   registration  = RegistrationType::New();<br>
                registration->SetMetric(        metric        );<br>
                registration->SetOptimizer(     optimizer     );<br>
                registration->SetInterpolator(  interpolator  );<br>
                registration->SetTransform( transform );<br>
<br>
                typedef itk::ImageFileReader<FixedImageType> FixedImageReaderType;<br>
                typedef itk::ImageFileReader<MovingImageType> MovingImageReaderType;<br>
<br>
                FixedImageReaderType::Pointer  fixedImageReader  =<br>
FixedImageReaderType::New();<br>
                MovingImageReaderType::Pointer movingImageReader =<br>
MovingImageReaderType::New();<br>
                fixedImageReader->SetFileName(source.c_str());<br>
                movingImageReader->SetFileName(target.c_str());<br>
<br>
<br>
                registration->SetFixedImage(fixedImageReader->GetOutput());<br>
                registration->SetMovingImage(   movingImageReader->GetOutput()   );<br>
<br>
                try{<br>
                        fixedImageReader->Update();<br>
                }catch(itk::ExceptionObject & excp){<br>
                        std::cerr << excp << std::endl;<br>
                }<br>
<br>
<br>
registration->SetFixedImageRegion(fixedImageReader->GetOutput()->GetBufferedRegion()<br>
);<br>
<br>
                typedef<br>
itk::CenteredTransformInitializer<TransformType,FixedImageType,MovingImageType><br>
TransformInitializerType;<br>
                TransformInitializerType::Pointer initializer =<br>
TransformInitializerType::New();<br>
<br>
                initializer->SetTransform(transform);<br>
                initializer->SetFixedImage(fixedImageReader->GetOutput());<br>
                initializer->SetMovingImage(movingImageReader->GetOutput());<br>
                initializer->MomentsOn();<br>
                initializer->InitializeTransform();<br>
<br>
                typedef TransformType::VersorType  VersorType;<br>
                typedef VersorType::VectorType     VectorType;<br>
                VersorType     rotation;<br>
                VectorType     axis;<br>
                axis[0] = 0.0;<br>
                axis[1] = 0.0;<br>
                axis[2] = 1.0;<br>
                const double angle = 0;<br>
                rotation.Set(  axis, angle  );<br>
                transform->SetRotation( rotation );<br>
<br>
                registration->SetInitialTransformParameters( transform->GetParameters() );<br>
<br>
                typedef OptimizerType::ScalesType       OptimizerScalesType;<br>
                OptimizerScalesType optimizerScales( transform->GetNumberOfParameters() );<br>
                const double translationScale = 1.0 / 1000.0;<br>
                optimizerScales[0] = 1.0;<br>
                optimizerScales[1] = 1.0;<br>
                optimizerScales[2] = 1.0;<br>
                optimizerScales[3] = translationScale;<br>
                optimizerScales[4] = translationScale;<br>
                optimizerScales[5] = translationScale;<br>
                optimizer->SetScales( optimizerScales );<br>
                optimizer->SetMaximumStepLength( 0.2000  );<br>
                optimizer->SetMinimumStepLength( 0.0001 );<br>
                optimizer->SetNumberOfIterations( iteration );<br>
<br>
                CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();<br>
                observer->GetTomo(this->in);<br>
                optimizer->AddObserver(itk::IterationEvent(),observer);<br>
<br>
                try{<br>
                        registration->Update();<br>
                        std::cout << "Optimizer stop condition: "<<<br>
registration->GetOptimizer()->GetStopConditionDescription()<< std::endl;<br>
                }<br>
                catch( itk::ExceptionObject & err ){<br>
                        std::cerr << "ExceptionObject caught !" << std::endl;<br>
                        std::cerr << err << std::endl;<br>
                }<br>
<br>
                OptimizerType::ParametersType finalParameters =<br>
registration->GetLastTransformParameters();<br>
                const double versorX              = finalParameters[0];<br>
                const double versorY              = finalParameters[1];<br>
                const double versorZ              = finalParameters[2];<br>
                const double finalTranslationX    = finalParameters[3];<br>
                const double finalTranslationY    = finalParameters[4];<br>
                const double finalTranslationZ    = finalParameters[5];<br>
                const unsigned int numberOfIterations = optimizer->GetCurrentIteration();<br>
                const double bestValue = optimizer->GetValue();<br>
<br>
                std::cout << std::endl << std::endl;<br>
                std::cout << " Result = " << std::endl;<br>
                std::cout << " versor X      = " << versorX  << std::endl;<br>
                std::cout << " versor Y      = " << versorY  << std::endl;<br>
                std::cout << " versor Z      = " << versorZ  << std::endl;<br>
                std::cout << " Translation X = " << finalTranslationX  << std::endl;<br>
                std::cout << " Translation Y = " << finalTranslationY  << std::endl;<br>
                std::cout << " Translation Z = " << finalTranslationZ  << std::endl;<br>
                std::cout << " Iterations    = " << numberOfIterations << std::endl;<br>
                std::cout << " Metric value  = " << bestValue          << std::endl;<br>
<br>
                transform->SetParameters( finalParameters );<br>
                TransformType::MatrixType matrix = transform->GetMatrix();<br>
                TransformType::OffsetType offset = transform->GetOffset();<br>
                std::cout << "Matrix = " << std::endl << matrix << std::endl;<br>
                std::cout << "Offset = " << std::endl << offset << std::endl;<br>
<br>
                vtkSmartPointer<vtkMatrix4x4> matrixOfTransformation =<br>
vtkSmartPointer<vtkMatrix4x4>::New();<br>
                for(unsigned int i=0;i<3;i++){<br>
                        for(unsigned int j=0;j<3;j++){<br>
                                matrixOfTransformation->SetElement(i,j,matrix(i,j));<br>
                        }<br>
                }<br>
                matrixOfTransformation->SetElement(0,3,versorX);<br>
                matrixOfTransformation->SetElement(1,3,versorY);<br>
                matrixOfTransformation->SetElement(2,3,versorZ);<br>
                matrixOfTransformation->SetElement(3,0,0);<br>
                matrixOfTransformation->SetElement(3,1,0);<br>
                matrixOfTransformation->SetElement(3,2,0);<br>
                matrixOfTransformation->SetElement(3,3,1);<br>
<br>
                cout<<"matrix from mutual information:<br>
"<<endl&lt;&lt;*matrixOfTransformation&lt;&lt;endl;<br>
<br>
                return matrixOfTransformation;<br>
}<br>
};<br>
<br>
<br>
<br>
class TomoRegistration : public QMainWindow, Ui::TomoRegistrationClass<br>
{<br>
public:<br>
void test(){<br>
typedef itk::ImageIOBase::IOComponentType ScalarPixelType;<br>
        itk::ImageIOBase::Pointer imageIOsource =<br>
itk::ImageIOFactory::CreateImageIO(&quot;writesource.mhd&quot;,itk::ImageIOFactory::ReadMode);<br>
        imageIOsource->SetFileName("writesource.mhd");<br>
        imageIOsource->ReadImageInformation();<br>
        const ScalarPixelType pixelTypeSource = imageIOsource->GetComponentType();<br>
<br>
        itk::ImageIOBase::Pointer imageIOtarget =<br>
itk::ImageIOFactory::CreateImageIO("writetarget.mhd",itk::ImageIOFactory::ReadMode);<br>
        imageIOtarget->SetFileName("writetarget.mhd");<br>
        imageIOtarget->ReadImageInformation();<br>
        const ScalarPixelType pixelTypeTarget = imageIOtarget->GetComponentType();<br>
<br>
vtkSmartPointer<vtkMatrix4x4> MatrixFromMutualInformation =<br>
MI->VolumeRegistration("writesource.mhd","writetarget.mhd",iteration,pixelTypeSource,pixelTypeTarget);<br>
}<br>
};<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://itk-users.7.n7.nabble.com/Set-the-right-pixelType-tp33171.html" target="_blank">http://itk-users.7.n7.nabble.com/Set-the-right-pixelType-tp33171.html</a><br>
Sent from the ITK - Users mailing list archive at Nabble.com.<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
_______________________________________________<br>
Community mailing list<br>
<a href="mailto:Community@itk.org">Community@itk.org</a><br>
<a href="http://public.kitware.com/cgi-bin/mailman/listinfo/community" target="_blank">http://public.kitware.com/cgi-bin/mailman/listinfo/community</a><br>
</blockquote></div><br></div>