<div><br></div>Hi James,<div><br></div><div><br></div><div>There are three easy methods for coloring an image of labels.</div><div><br></div><div><br></div><div>Method A:</div><div><br></div><div>    Use the method illustrated in the example:</div>
<div><br></div><div>            Insight/Examples/Segmentation/WatershedSegmentation1.cxx</div><div><br></div><div>    namely:</div><div><br></div><div><div>  typedef itk::Functor::ScalarToRGBPixelFunctor&lt;unsigned long&gt;</div>
<div>    ColorMapFunctorType;</div><div>  typedef itk::UnaryFunctorImageFilter&lt;LabeledImageType,</div><div>    RGBImageType, ColorMapFunctorType&gt; ColorMapFilterType;</div><div>  ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();</div>
<div><br></div></div><div><br></div><div><br></div><div>Method B:</div><div><br></div><div>    Use the tkScalarToRGBColormapImageFilter.h class in the</div><div>    directory:</div><div><br></div><div>               Insight/Code/Review</div>
<div><br></div><div>     This filter is described in the following Insight Journal paper:</div><div><br></div><div>           <a href="http://www.insight-journal.org/browse/publication/285">http://www.insight-journal.org/browse/publication/285</a></div>
<div><br></div><div><br></div><div><br></div><div><br></div><div>Method C:</div><div><br></div><div>     Use the filter </div><div><br></div><div>              Insight/Code/Review/</div><div>                      itkLabelToRGBImageFilter.h</div>
<div><br>      that is described in the Insight Journal paper:</div><div><br></div><div>                <a href="http://www.insight-journal.org/browse/publication/176">http://www.insight-journal.org/browse/publication/176</a></div>
<div><br></div><div><br></div><div><br></div><div>If you are planning on doing extensive work with labeled images,</div><div>you may want to use Method C, and get familiar with the associated</div><div>Insight Journal paper, since it provides a very rich collection of classes</div>
<div>and filters for dealing with labeled images.</div><div><br></div><div><br></div><div>          Regards,</div><div><br></div><div><br></div><div>                Luis</div><div><br></div><div><br></div><div>--------------------------------------------------------------------------------------<br>
<div class="gmail_quote">On Thu, Dec 3, 2009 at 5:36 AM, Malsoaz James <span dir="ltr">&lt;<a href="mailto:jmalsoaz@yahoo.fr">jmalsoaz@yahoo.fr</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit">Hello, I&#39;m trying to label a binary image. For that, I have been using ConnectedComponentImageFilter and RelabelComponentImageFilter with no problem apparently.<br>
<br>I&#39;m able to get the number of objects and the size of them. But I can&#39;t figure out how to display the objects found in the image with different levels of gray (prefered solution) or different colors. Indeed, I&#39;m getting an almost black image where I can difficultly distinguish the objects.<br>
<br>I would really appreciate some help to solve this.<br>Thank you.<br>James<br><br>By the way, here is my code:<br><br>typedef unsigned char PixelType;<br>typedef itk::Image&lt;PixelType, 2&gt; ImageType;<br>typedef itk::ImageFileReader&lt;ImageType&gt; ReaderType;<br>
typedef itk::ImageFileWriter&lt;ImageType&gt; WriterType;<br>typedef itk::ConnectedComponentImageFilter &lt;ImageType, ImageType&gt;
 LabelType;<br>typedef itk::RelabelComponentImageFilter &lt;ImageType, ImageType&gt; RelabelType;<br><br><br>int main(int argc, char *argv[])<br>{<br>    ReaderType::Pointer reader = ReaderType::New();<br>    WriterType::Pointer writer = WriterType::New();<br>
    LabelType::Pointer labeler = LabelType::New();<br>    RelabelType::Pointer relabeler = RelabelType::New();<br><br>    reader-&gt;SetFileName(&quot;input.bmp&quot;);<br><br>    labeler-&gt;SetInput(reader-&gt;GetOutput());<br>
    labeler-&gt;Update();<br><br>    relabeler-&gt;SetInput(labeler-&gt;GetOutput());<br>    relabeler-&gt;Update();<br><br>    for (unsigned int i=0; i&lt;relabeler-&gt;GetNumberOfObjects(); i++)<br>    {<br>        std::cout&lt;&lt;&quot;Number of pixel for object &quot;&lt;&lt;i&lt;&lt;&quot;:
 &quot;&lt;&lt;relabeler-&gt;GetSizeOfObjectsInPixels()[i]&lt;&lt;std::endl;<br>    }<br>    writer-&gt;SetFileName(&quot;output.bmp&quot;);<br>    writer-&gt;SetInput(relabeler-&gt;GetOutput());<br>    writer-&gt;Update();<br>
    return EXIT_SUCCESS;<br><br>}<br></td></tr></tbody></table><br>




      <br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br></div>