Hi,<br>I have  a problem to construct a binary image. I want to segment the lung regions of DICOM image, so I compute a gray-level histogram, and the gray-level that maximizes the separation between the two major peaks in the histogram is selected as the gray-level threshold to compute the binary image.<br>
I compute the histogram and then I smoothing because I have a lot of peaks in this way, I transform the values of the histogram in an Image 1d (thanks a Luis):<br><br>int * createImage(int *valoresHisto){<br>    <br>    //creamos la imagen 1d<br>
    size1D.Fill( 255 );<br>    start1D.Fill( 0 );<br>    region1D.SetSize( size1D );<br>    region1D.SetIndex( start1D );<br>    line-&gt;SetRegions( region1D );<br>    line-&gt;Allocate();<br>    <br>    IteratorType lineIt(line, line-&gt;GetRequestedRegion());<br>
    int i = 0;<br>    //rellenamos la imagen con los valores del histograma<br>    for (lineIt.GoToBegin(); !lineIt.IsAtEnd();<br>    ++lineIt)<br>    {<br>        lineIt.Set( valoresHisto[i]);<br>        i=i+1;<br>    }<br>
    <br>    <br>    typedef itk::ImageFileWriter&lt; ImageType1D &gt; WriterType1D;<br>    WriterType1D::Pointer writer1D = WriterType1D::New();<br>    writer1D-&gt;SetFileName( &quot;Image1D.png&quot; );<br>    writer1D-&gt;SetInput( line );<br>
    try<br>    {<br>        writer1D-&gt;Update();<br>    }<br>    catch (itk::ExceptionObject &amp;e)<br>    {<br>        std::cerr &lt;&lt; e &lt;&lt; std::endl;<br>        <br>    }<br>    <br>    smoothingFilter-&gt;SetSigma( 5 ); <br>
    smoothingFilter-&gt;SetInput( line );<br>    smoothingFilter-&gt;Update();<br>    ImageType1D::Pointer image= smoothingFilter-&gt;GetOutput() ;    <br>    ImageType1D::ConstPointer inputImage =smoothingFilter-&gt;GetOutput() ;<br>
    ImageType1D::RegionType inputRegion =inputImage-&gt;GetBufferedRegion();<br>    IteratorType  iterator( image, inputRegion);<br>    <br>    static int valoresSuavizado[512];<br>    i=0;<br>    for (iterator = iterator.Begin(); !iterator.IsAtEnd(); ++iterator)<br>
    {<br>       std::cout&lt;&lt; iterator.Get()&lt;&lt; std::endl;<br>        valoresSuavizado[i]=iterator.Get();<br>        i=i+1;<br>    }<br>    <br>    return valoresSuavizado;<br>}<br><br><br><br>But I have problem with the first values, because there are higher values, I use sigma=5.  <br>
Another question is about to calculate the threshold, somebody can suggest me how I can compute that.<br><br>Thanks a lot.<br><br>