[Insight-users] [Question] 3D Fill

Maximilien Renard iixamaxii at gmail.com
Sat Jul 25 06:17:14 EDT 2009


Hi there,

I'm trying to realize a function (Fill3D) that uses the connected
threshold filter to fill a region of a 3D image with another value
based on a threshold.

This is the function I'm using now :

void CVolumeData::Fill3D(int X, int Y, int Z, unsigned short
LowThreshold, unsigned short HighThreshold, unsigned short
ReplacementValue) {
	typedef itk::ConnectedThresholdImageFilter < ITK3DImageType,
ITK3DImageType> FilterType;
	FilterType::Pointer filter = FilterType::New();
	ITK3DImageType::IndexType seed;
	seed[0] = X;
	seed[1] = Y;
	seed[2] = Z;
	CVolumeData *pResultImage;
	int DimX, DimY, DimZ, x, y, z;

	filter->SetSeed(seed);
	filter->SetLower(LowThreshold);
	filter->SetUpper(HighThreshold);
	filter->SetReplaceValue(4000);

	filter->SetInput(GetITK3DImage());
	filter->Update();
	pResultImage = new CVolumeData(m_MainView);
	pResultImage->SetITK3DImage(filter->GetOutput());

	GetDimensions(DimX, DimY, DimZ);

	for (z = 0; z < DimZ; z++)
		for (y = 0; y < DimY; y++)
			for (x = 0; x < DimX; x++) {
				if (pResultImage->GetVoxel(x, y, z) >= 4000) {
					SetVoxel(x, y, z, ReplacementValue);
				}
			}

	delete(pResultImage);
}

The last 3 for (DimZ, DimY and DimX) are necessary to replace the
filled zone in the original image without replacing the zone of the
original image which lies outside the threshold values. Sadly it takes
lots of time. Is there a better way to do this ?

Next question, I need to do a Fill2D function too. Here again I have a
problem. I use the extract image filter to extract the slice I need,
then I apply the Fill3D filter on the image (Fill3D that doesn't work
properly now) and what I wanted to do is use the PasteImageFilter to
paste the result of the Fill3D (which has only one slice) back into
the original 3D Image.

But once again it doesn't work. The result is that the new slice is
entirely black...

void CVolumeData::Fill2D(int X, int Y, int Z, unsigned short
LowThreshold, unsigned short HighThreshold, unsigned short
ReplacementValue, int SubView) {
	int DimX, DimY, DimZ;
	int x, y, z;

	GetDimensions(DimX, DimY, DimZ);

	typedef itk::ExtractImageFilter< ITK3DImageType, ITK3DImageType > FilterType;
	FilterType::Pointer filter = FilterType::New();

	ITK3DImageType::RegionType inputRegion =
GetITK3DImage()->GetLargestPossibleRegion();

	if (SubView == CMainView::MODE_XY) {
		CVolumeData SliceVolume(m_MainView);

		SliceVolume.CreateVolume(DimX, DimY, 1, 1.0f, 1.0f, 1.0f, 0, false);

		ITK3DImageType::SizeType size = inputRegion.GetSize();
		size[2] = 1;
		ITK3DImageType::IndexType start = inputRegion.GetIndex();
		start[2] = Z;
		ITK3DImageType::RegionType desiredRegion;
		desiredRegion.SetSize(size);
		desiredRegion.SetIndex(start);

		filter->SetExtractionRegion(desiredRegion);

		filter->SetInput(GetITK3DImage());

		filter->Update();

		SliceVolume.SetITK3DImage(filter->GetOutput());

		SliceVolume.Fill3D(X, Y, 0, LowThreshold, HighThreshold, ReplacementValue);

		typedef itk::PasteImageFilter< ITK3DImageType, ITK3DImageType,
ITK3DImageType > ImageReplacementFilterType;
		ImageReplacementFilterType::Pointer ImageReplacementFilter =
ImageReplacementFilterType::New();

		ImageReplacementFilter->SetSourceImage(SliceVolume.GetITK3DImage());
		ImageReplacementFilter->SetSourceRegion(SliceVolume.GetITK3DImage()->GetLargestPossibleRegion());

		ImageReplacementFilter->SetDestinationImage(GetITK3DImage());
		ImageReplacementFilter->SetDestinationIndex(start);

		ImageReplacementFilter->Update();
		SetITK3DImage(ImageReplacementFilter->GetOutput());
	}
}

I'd enjoy any kind of help !

Thank you very much,

Best regards,


Maximilien Renard


More information about the Insight-users mailing list