[Insight-users] Number and size of regions?

Dan Mueller d.mueller at qut.edu.au
Tue Mar 27 15:52:03 EST 2007


Hi Christian,

Have a look at the following filters:
    
http://www.itk.org/Doxygen/html/classitk_1_1ConnectedComponentImageFilter.html
    
http://www.itk.org/Doxygen/html/classitk_1_1RelabelComponentImageFilter.html

A pipeline doing what you need could look something like this:
    ConnectedComponent > RelabelComponent

The ConnectedComponentImageFilter will firstly label each blob in your 
3D image with a
unique value. The RelabelComponentImageFilter will then re-order these 
labels to make
them consecutive. It has the method GetSizeOfObjectInPixels(..) which 
returns the size
for the given label value. Looping from 1 to GetNumberOfObjects() will 
enable you to determine
the size for each object (note that the background has label 0).

The LabelStatisticsImageFilter may also be of use:
    
http://www.itk.org/Doxygen/html/classitk_1_1LabelStatisticsImageFilter.html

HTH

Cheers, Dan

Christian Marshall Rieck wrote:
> Is there any way of getting the number and sizes of different regions in 
> an image? I have thresholded it and have a binary image with black 
> background with 1..N white (val=255) blobs in 3D. 
>
> I tried to iterate through it and look for values of 255, and if found 
> deliver this to a neighborhoodfilter to set it to a unique value. (then 
> value++). 
> Then the final value of value would give me the number of segments and a 
> histogram of the resulting image would give me the size of the regions. 
> However, this does not work. I pass the image::pointer to the 
> markRegions-function but the changes made there is not detected back in 
> the iteration. MarkRegion is called the number of white voxels in the 
> original image. 
>
> Code:
>
>
> template<class ImageType>
> int markDifferentSegments(typename ImageType::Pointer image){
>
> 	std::cout << "called markDifferent" << std::endl;
> 	typedef itk::ImageRegionIterator<ImageType> itType;
> 	ImageType::IndexType index;
> 	int color = 1;
> 	itType it(image, image->GetRequestedRegion());
> 	it.GoToBegin();
> 	while(!(it.IsAtEnd())) {
> 		if(it.Get() == 255) {
> 			markRegion<ImageType>(image, color, 
> it.GetIndex());
> 			color++;
> 		}
> 		++it;
> 	}
>
> 	std::cout << (color-1) << " regioner funnet. " << std::endl;
> 	WriteImageFile<ImageType>(image, "markTest.mhd");
> 	return color;
> }
>
>
> template<class ImageType>
> typename ImageType::Pointer markRegion(typename ImageType::Pointer image, 
> int color, typename ImageType::IndexType index) {
>
> 	ImageType::Pointer ret;
> 	typedef itk::NeighborhoodConnectedImageFilter<ImageType, 
> ImageType> neighType;
> 	neighType::Pointer neigh = neighType::New();
> 	neigh->SetInput(image);
> 	neigh->SetSeed(index);
> 	neigh->SetReplaceValue(color);
>
> 	ImageType::SizeType radius;
> 	radius[0] = 0;
> 	radius[1] = 0;
> 	radius[2] = 0;
> 	neigh->SetRadius(radius);
>
> 	ImageType::Pointer ret = neigh->GetOutput();
> 	try{
> 		ret->Update();
> 	}
> 	catch(itk::ExceptionObject &exep) {
> 		std::cerr << exep;
> 	}
>
>
> 	std::cout << "returning " << color << std::endl; 
> 	return ret;
> }
>
>
>
> best regards,
> Christian Marshall Rieck
> 93 49 54 75
> ----------------------------------------
> All the good things in life are
> fattening, cancer-causing or NP-complete.
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070328/5cba3cd6/attachment.htm


More information about the Insight-users mailing list