<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<small><font face="Helvetica, Arial, sans-serif">Hi Christian,<br>
<br>
Have a look at the following filters:<br>
<a class="moz-txt-link-freetext" href="http://www.itk.org/Doxygen/html/classitk_1_1ConnectedComponentImageFilter.html">http://www.itk.org/Doxygen/html/classitk_1_1ConnectedComponentImageFilter.html</a><br>
<a class="moz-txt-link-freetext" href="http://www.itk.org/Doxygen/html/classitk_1_1RelabelComponentImageFilter.html">http://www.itk.org/Doxygen/html/classitk_1_1RelabelComponentImageFilter.html</a><br>
<br>
A pipeline doing what you need could look something like this:<br>
ConnectedComponent > RelabelComponent<br>
<br>
The ConnectedComponentImageFilter will firstly label each blob in your
3D image with a <br>
unique value. The RelabelComponentImageFilter will then re-order these
labels to make <br>
them consecutive. It has the method GetSizeOfObjectInPixels(..) which
returns the size<br>
for the given label value. Looping from 1 to GetNumberOfObjects() will
enable you to determine<br>
the size for each object (note that the background has label 0).<br>
<br>
The LabelStatisticsImageFilter may also be of use:<br>
<a class="moz-txt-link-freetext" href="http://www.itk.org/Doxygen/html/classitk_1_1LabelStatisticsImageFilter.html">http://www.itk.org/Doxygen/html/classitk_1_1LabelStatisticsImageFilter.html</a><br>
<br>
HTH<br>
<br>
Cheers, Dan<br>
<br>
Christian Marshall Rieck wrote:</font></small>
<blockquote
cite="midPine.LNX.4.63.0703271639560.9884@gaupe.stud.ntnu.no"
type="cite">
<pre wrap="">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
<a class="moz-txt-link-abbreviated" href="mailto:Insight-users@itk.org">Insight-users@itk.org</a>
<a class="moz-txt-link-freetext" href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a></pre>
</blockquote>
</body>
</html>