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->SetRegions( region1D );<br> line->Allocate();<br> <br> IteratorType lineIt(line, line->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< ImageType1D > WriterType1D;<br> WriterType1D::Pointer writer1D = WriterType1D::New();<br> writer1D->SetFileName( "Image1D.png" );<br> writer1D->SetInput( line );<br>
try<br> {<br> writer1D->Update();<br> }<br> catch (itk::ExceptionObject &e)<br> {<br> std::cerr << e << std::endl;<br> <br> }<br> <br> smoothingFilter->SetSigma( 5 ); <br>
smoothingFilter->SetInput( line );<br> smoothingFilter->Update();<br> ImageType1D::Pointer image= smoothingFilter->GetOutput() ; <br> ImageType1D::ConstPointer inputImage =smoothingFilter->GetOutput() ;<br>
ImageType1D::RegionType inputRegion =inputImage->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<< iterator.Get()<< 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>