[Insight-users] Problems using Transforms and Filters

Rob Bijman lambikjes@hotmail.com
Thu May 6 09:47:10 EDT 2004


Dear Luis and other ITK users,

first of all I want to thank you for your help!

The pictures I am registrating are indeed from a camera (digital camera from 
canon).
For the multicolor images I shall try to use the solutions you gave me.

For the problems I have with the Binary Treshold Filter (and other filters), 
I couldn't send an attachment in Word format with some program parameters, 
so I put it in the end of the e-mail  The parameters used for the filter 
have been put inside "/" signs like:

//////////////
Filter Tekst
//////////////

Without using these parameters for the filter the program works without 
errors.
The error I get when I push a button to registrate two pictures is:
"Runtime Error, Program C:\.... , abnormal program termination".
I hope that you can help me further with this. I woulb be very happy.

With kind regards,

Rob Bijman






>From: Luis Ibanez <luis.ibanez@kitware.com>
>To: Rob Bijman <lambikjes@hotmail.com>
>CC: insight-users@itk.org
>Subject: Re: [Insight-users] Problems using Transforms and Filters
>Date: Tue, 04 May 2004 10:25:19 -0400
>
>
>Hi Rob,
>
>
>Welcome to ITK !,
>
>
>
>A) About multicolor images:  I assume that you are using RGB or RGBA
>    images.  Note that the image metrics available in ITK at this point
>    are for escalar images, that is, grayscale images or simply images
>    with a single component.  We have performed registration of color
>    images by using the two following methods:
>
>    A.1)  Extracting one channel from the color image, for example the
>          red channed, and using it as a scalar image for performing
>          registration.
>
>    A.2)  Converting the color image into a grayscale image by computing
>          a linear combination of its color components.
>
>    Both of this operations can be performed by creating a filter
>    that derives from the UnaryFunctorFitler or by using
>    ImageAdaptors. You will find a description on how to do this in
>    Chapter 12 of the software guide.
>
>
>    Of course, you could be more creative and do:
>
>    A.3) Implement an image metric customized for color images. In that
>         case you should take a look at the actual code of the image to
>         image metrics in Insight/Code/Algorithms
>
>
>BTW, why are you getting color images if you are working with
>patients that are being X-rayed ?
>
>Are you using a video camera for taking an external view of the
>patient ?
>
>If that's the case, you should rather look into using a motion
>detection method such as the DemonsRegistration filter:
>
>http://www.itk.org/Insight/Doxygen/html/classitk_1_1DemonsRegistrationFilter.html
>
>You should still convert your color images to grayscale, unless
>you think that there are valuable information encoded in the color.
>
>
>
>
>
>B)  We will be more than happy to help you with the problem
>     that you have when introducing the threshold filter in
>     your program. Unfortunately our divinatory capabilities
>     have been seriously deteriorated by excesive use. It will
>     therefore be very helpful if you could share with us some
>     interesting details of your code such as:
>
>     C.1) The error messages that you get when your program fails.
>     C.2) The kind of processing that you are attempting to perform.
>     C.3) The mechanism that you used for passing your image to ITK.
>     C.4) An actual piece of code will be greatly appreciated.
>
>
>
>Best regards,
>
>
>    Luis
>
>
>-----------------
>Rob Bijman wrote:
>
>>Dear ITK users,
>>
>>I am working for the MST Hospital in the Netherlands and I am trying to 
>>use ITK for a registration process. It's my job to develop a program that 
>>notices movements of patients when they are being x-rayed.
>>The problem is that the values I get from the transforms I use (Affine 
>>Transform / Translation Transform) do not match with the theoretical 
>>values when I use 'real' multicolor images. I used the ITK software guide 
>>and have put the transforms inside the program exactly the way it has been 
>>described. It only works when using example pictures from ITK 1.6.0, and 
>>the rotation from the Affine Transform doesn't work at all (very strange 
>>values). Does anyone have some extra documentation for me, or some help?
>>The second problem is the use of filters. When I put filters (for example 
>>the binary tresholdfilter) into the program, like described in the ITK 
>>software guide, the program runs normally, but when I start the 
>>registration the program returns an error.
>>It would be very nice if someone has got some extra information for this. 
>>I hope that what I described above is clear enough.
>>
>>With kind regards,
>>
>>Rob Bijman
>>MST Enschede, Netherlands
>>
>
>
>
>_______________________________________________
>Insight-users mailing list
>Insight-users@itk.org
>http://www.itk.org/mailman/listinfo/insight-users


////////////////////////////////Binary Treshold Image 
Filter/////////////////////////////////////////////////////
if (m_Eerste = TRUE)
{

const unsigned int Dimension = 2;
typedef float PixelType;
//////////////
typedef unsigned char InputPixelType;
typedef unsigned char OutputPixelType;
typedef itk::Image< InputPixelType, 2 > InputImageType;
///////////
typedef itk::Image< OutputPixelType, 2 > OutputImageType;
////////////
typedef itk::Image< PixelType, Dimension > 				FixedImageType;
typedef itk::Image< PixelType, Dimension > 				MovingImageType;

typedef itk::TranslationTransform< double, Dimension > 			TransformType;
typedef itk::RegularStepGradientDescentOptimizer	 			OptimizerType;
typedef itk::MattesMutualInformationImageToImageMetric<
			FixedImageType,
			MovingImageType >	 			MetricType;
typedef itk:: LinearInterpolateImageFunction<
			MovingImageType,
			double > 					InterpolatorType;
typedef itk::ImageRegistrationMethod<
			FixedImageType,
			MovingImageType >				RegistrationType;

//////////////////////////////////////////////////////////////////////////////////
typedef itk::BinaryThresholdImageFilter<										//
			InputImageType, OutputImageType > FilterType;                       //
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< InputImageType > WriterType;
//////////////////////////////////////////////////////////////////////////////////
MetricType::Pointer metric = MetricType::New();
TransformType::Pointer transform = TransformType::New();
OptimizerType::Pointer optimizer = OptimizerType::New();
InterpolatorType::Pointer interpolator = InterpolatorType::New();
RegistrationType::Pointer registration = RegistrationType::New();

///////////////////////////////////////////////////
ReaderType::Pointer reader = ReaderType::New();//
FilterType::Pointer filter = FilterType::New();//
///////////////////////////////////////////////////

registration->SetMetric(	 	metric 		);
registration->SetOptimizer(	 	optimizer		);
registration->SetTransform(	 	transform		);
registration->SetInterpolator(	 	interpolator	);

typedef itk::ImageFileReader< FixedImageType  > FixedImageReaderType;
typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;

FixedImageReaderType::Pointer  fixedImageReader  = 
FixedImageReaderType::New();
MovingImageReaderType::Pointer movingImageReader = 
MovingImageReaderType::New();

fixedImageReader->SetFileName(  	m_sRef	 );
movingImageReader->SetFileName( 	m_sBew	 );
UpdateData(FALSE);

registration->SetFixedImage(		 fixedImageReader->GetOutput()	 );
registration->SetMovingImage(	 movingImageReader->GetOutput()	 );

fixedImageReader->Update();
movingImageReader->Update();

registration->SetFixedImageRegion(
	fixedImageReader->GetOutput()->GetBufferedRegion() );

typedef RegistrationType::ParametersType ParametersType;
ParametersType initialParameters( transform->GetNumberOfParameters() );

initialParameters[0] = 0.0; // Initial offset in mm along X
initialParameters[1] = 0.0; // Initial offset in mm along Y

registration->SetInitialTransformParameters( initialParameters );

////////////////////////////////////////////
filter->SetInput( reader->GetOutput() );//
filter->SetOutsideValue(0);			  //
filter->SetInsideValue(120);            //
filter->SetLowerThreshold( 180 );       //
filter->SetUpperThreshold( 180 );       //
filter->Update();                       //
////////////////////////////////////////////

optimizer->SetMaximumStepLength( 4.00 );	//4.00
optimizer->SetMinimumStepLength( 0.001 );	//0.005
optimizer->SetNumberOfIterations( 200 );	//200

metric->SetNumberOfHistogramBins( 20 );		//20
metric->SetNumberOfSpatialSamples( 10000 );	//10000

try
{
registration->StartRegistration();
}
catch(...)
{
m_sTekst= "Dit gaat fout";
}


ParametersType finalParameters = registration->GetLastTransformParameters();

const double TranslationAlongX = finalParameters[0];

const double TranslationAlongY = finalParameters[1];

const unsigned int numberOfIterations = 50; 
//optimizer->GetCurrentIteration();

const double bestValue = optimizer->GetValue();


//int m_dOpt;
//int m_dNumIt;
m_dTransX = TranslationAlongX;
m_dTransY = TranslationAlongY;
m_sTekst = "Bijstellen";
//m_dOpt = 0;
//m_dRot = 0;
UpdateData(FALSE);

_________________________________________________________________
Hotmail en Messenger on the move 
http://www.msn.nl/communicatie/smsdiensten/hotmailsmsv2/




More information about the Insight-users mailing list