[Insight-users] Gaussian smoothing of an RGB image

Chris Farmer cfarmer at scitegic.com
Tue Oct 25 11:30:53 EDT 2005


Hi.  I'd like to perform a Gaussian blur type smoothing operation on an RGB image.  In the archives, I saw that James Miller recommended using a VectorNeighborhoodOperatorImageFilter with a GaussianOperator (http://www.itk.org/pipermail/insight-users/2004-August/010108.html) for this purpose.  As he suggested, I tried to model my code on the itkPDEDeformableRegistrationFilter::SmoothDeformationField() method, but all I seem to ever get as output is a black image.  Could someone please look at this code to see if I'm just doing something dumb?  I suspect I'm losing something in the swapping steps.

Thanks,
Chris


typedef itk::VectorNeighborhoodOperatorImageFilter<RGB8ImageType, RGB8ImageType> SmoothingFilterType;
SmoothingFilterType::Pointer smoother = SmoothingFilterType::New();
	
RGB8ImageType::Pointer tmpimage = RGB8ImageType::New();
tmpimage->SetSpacing(m_rgb8image->GetSpacing());
tmpimage->SetOrigin(m_rgb8image->GetOrigin());
tmpimage->SetLargestPossibleRegion(m_rgb8image->GetLargestPossibleRegion());
tmpimage->SetRequestedRegion(m_rgb8image->GetRequestedRegion());
tmpimage->SetBufferedRegion(m_rgb8image->GetBufferedRegion());
tmpimage->Allocate();

typedef itk::GaussianOperator<unsigned char> OperatorType;
OperatorType gaussian;

typedef RGB8ImageType::PixelContainerPointer PixelContainerPointer;
PixelContainerPointer swapPtr;

smoother->GraftOutput(tmpimage);

for (int i=0; i<2; i++)
{
	gaussian.SetDirection(i);
	gaussian.SetVariance(variance);
	gaussian.SetMaximumError(maxerror);
	gaussian.SetMaximumKernelWidth(maxkernelwidth);
	gaussian.CreateDirectional();
		
	smoother->SetOperator(gaussian);
	smoother->SetInput(m_rgb8image);
	smoother->Update();

	if ( i<1 )
	{
		// swap the containers
		swapPtr = smoother->GetOutput()->GetPixelContainer();
		smoother->GraftOutput(m_rgb8image);
		m_rgb8image->SetPixelContainer(swapPtr);
		smoother->Modified();
	}
}

tmpimage->SetPixelContainer(m_rgb8image->GetPixelContainer());
m_rgb8image = smoother->GetOutput();
 



More information about the Insight-users mailing list