[Insight-users] Watershed Segmentation - problem running itkWSRawToPNG.cxx

neha k itkneha1 at yahoo.com
Fri, 27 Feb 2004 16:40:57 -0800 (PST)


--0-1803944301-1077928857=:96858
Content-Type: text/plain; charset=us-ascii

Hi Luis,
 
Due to problem in example program itkWSRawToPNG.cxx, I have written following simple code for experiment to work on RAW grayscale file.   I am using this pipeline of filters->
reader--->AnisotropicDiffusionFilter--->GradientMagnitudeFilter--->WaterShed
 
Problem is : Output file is of "0" Bytes.   But From GradientMagnitudeFilter, I get desired output.  But watershed does not give output file of original input size, instead it is Zero.
I tried with 3 different values for conductance_term, threshold and Level.  But still the output file has 0 bytes.
 
Please let me know if I am missing anything while using watershed.
 
Following the simple code i am using ->
***********************************************************************************

void segment()

{

// declarations

int threshold = 0.30, floodLevel = 0.50;

int noOfIterations = 3, retVal = 1, checkExtn =0;

char answer='y', inputFile[255]="breast.mhd", outputFile[255]="breast_op.mhd";

float timeStep = 0.25, 

conductance = 5.0;



typedef itk::Image< InputPixelType, 2 > InputImageType; // float type

typedef itk::Image< OutputPixelType, 2 > OutputImageType; // float type

typedef itk::Image<unsigned long, 2> LabeledImageType; 

typedef itk::Image<float, 2> ScalarImageType;

typedef itk::Image<unsigned long, 2> WriteImageType; 

typedef itk::GradientAnisotropicDiffusionImageFilter<InputImageType, OutputImageType > FilterType;

FilterType::Pointer filter = FilterType::New();

// Instantiate Gradient Magnitude Filter typedef itk::GradientMagnitudeImageFilter<InputImageType, OutputImageType>

GradientFilterType;

GradientFilterType::Pointer gradientFilter = GradientFilterType::New(); 

typedef itk::WatershedImageFilter<ScalarImageType> WatershedFilterType;

WatershedFilterType::Pointer watershed = WatershedFilterType::New(); 

typedef itk::ImageFileWriter< WriteImageType > WriterType; // write output image as short - use rescaler 

WriterType::Pointer writer = WriterType::New();

typedef itk::ImageFileReader< InputImageType > ReaderType; // read input image as float

ReaderType::Pointer reader = ReaderType::New();



reader->SetFileName(inputFile); 

writer->SetFileName( outputFile );

// Read Input Image of RAW Type (uses MetaImage Header)

try { reader->Update(); }

catch( itk::ExceptionObject & e ) {

std::cerr << "Exception caught during Raw file reading " << std::endl;

std::cerr << e << std::endl;

std::cout<< "\n\nMake Sure if the file name you specified already exists...\n"; 

return -1;

} 



// First apply Edge Preserving smoothing filter "Anisotropic Diffusion Filter"

filter->SetInput( reader->GetOutput() ); 

filter->SetIterations(noOfIterations); // default value -> 3

filter->SetConductanceParameter(conductance); // default value -> 5.0

filter->SetTimeStep(timeStep); // default value -> 0.25 for 2-D image 

// Pass the output of Anisotropic Diffusion Filter to GradientMagnitudeFilter

gradientFilter->SetInput( filter->GetOutput() );

// Apply Watershed Segmentation

watershed->SetInput(gradientFilter->GetOutput()); 

watershed->SetThreshold(threshold); // 0.30

watershed->SetLevel(floodLevel); // 0.50 

writer->SetInput(watershed->GetOutput()); 



// Execute the pipeline

try { writer->Update(); }

catch( itk::ExceptionObject & excep ){

std::cerr << "Exception caught !" << std::endl;

std::cerr << excep << std::endl;

retVal = -1;

} 

}

 
***********************************************************************************

Joshua Cates <cates at sci.utah.edu> wrote:
Hi,

Thanks for the feedback on the watershed example. This code is old and 
probably in need of updating for more recent developments in the ITK IO 
classes. I will take a look.

Josh.

On Mon, 23 Feb 2004, neha k wrote:

> 
> Hi All,
> 
> I am trying to run exampleI programs in Watershed segmetnation. I tried
> the example program with Input file as PGM file (in.pgm) which is of
> size (24*7). When I run itkWatershedSegmentationExample.cxx, I get 5
> output files of raw format (with level = 0.50). When I set any of those
> 5 output files as an input file to second program itkWSRawToPNG.cxx so
> that I can convert it to png file to view, program crashes( on statement
> reader_update()). What should be the input file given to this second
> program? Also, if i want to segment the raw brest images, what reader
> should I use and how should i generate the output files? What filters,
> mappers should I use to apply watershed segmentation on grayscale breast
> images of Raw format to find out if there is any lesion inside the brest
> image? (Currently, I am using MetaImageReader to apply other ITK filters
> on breast images.)
> 
> Any suggestions are appreiated.
> 
> My input PGM file is as follows
> 
> ***************************************************************************************
> 
> P2
> 
> 24 7
> 
> 15
> 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 
> 0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
> 
> 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
> 
> 0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0
> 
> 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0
> 
> 0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0
> 
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 
> 
> 
> *************************************************************************************** 
> 
> Thanks,
> 
> Neha
> 
> 
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Mail SpamGuard - Read only the mail you want.

_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users

---------------------------------
Do you Yahoo!?
Get better spam protection with Yahoo! Mail
--0-1803944301-1077928857=:96858
Content-Type: text/html; charset=us-ascii

<DIV>Hi Luis,</DIV>
<DIV>&nbsp;</DIV>
<DIV>Due to problem in example program itkWSRawToPNG.cxx, I have written following simple code for experiment to work on RAW grayscale file.&nbsp;&nbsp; I am using this pipeline of filters-&gt;</DIV>
<DIV>reader---&gt;AnisotropicDiffusionFilter---&gt;GradientMagnitudeFilter---&gt;WaterShed</DIV>
<DIV>&nbsp;</DIV>
<DIV>Problem is : Output file is of "0" Bytes.&nbsp;&nbsp; But From GradientMagnitudeFilter, I get desired output.&nbsp; But watershed does not give output file of original input size, instead it is Zero.</DIV>
<DIV>I tried with 3 different values for conductance_term, threshold and Level.&nbsp; But still the output file has 0 bytes.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Please let me know if I am missing anything while using watershed.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Following the simple code i am using -&gt;</DIV>
<DIV>***********************************************************************************<BR><FONT size=2>
<P>void segment()</P>
<P>{</P>
<P><U>// declarations</U></P>
<P>int threshold = 0.30, floodLevel = 0.50;</P>
<P>int noOfIterations = 3, retVal = 1, checkExtn =0;</P>
<P>char answer='y', inputFile[255]="breast.mhd", outputFile[255]="breast_op.mhd";</P>
<P>float timeStep = 0.25, </P>
<P>conductance = 5.0;</P>
<P></P>
<P>typedef itk::Image&lt; InputPixelType, 2 &gt; InputImageType; // float type</P>
<P>typedef itk::Image&lt; OutputPixelType, 2 &gt; OutputImageType; // float type</P>
<P>typedef itk::Image&lt;unsigned long, 2&gt; LabeledImageType; </P>
<P>typedef itk::Image&lt;float, 2&gt; ScalarImageType;</P>
<P>typedef itk::Image&lt;unsigned long, 2&gt; WriteImageType; </P>
<P>typedef itk::GradientAnisotropicDiffusionImageFilter&lt;InputImageType, OutputImageType &gt; FilterType;</P>
<P>FilterType::Pointer filter = FilterType::New();</P>
<P>// Instantiate Gradient Magnitude Filter typedef itk::GradientMagnitudeImageFilter&lt;InputImageType, OutputImageType&gt;</P>
<P>GradientFilterType;</P>
<P>GradientFilterType::Pointer gradientFilter = GradientFilterType::New(); </P>
<P>typedef itk::WatershedImageFilter&lt;ScalarImageType&gt; WatershedFilterType;</P>
<P>WatershedFilterType::Pointer watershed = WatershedFilterType::New(); </P>
<P>typedef itk::ImageFileWriter&lt; WriteImageType &gt; WriterType; // write output image as short - use rescaler </P>
<P>WriterType::Pointer writer = WriterType::New();</P>
<P>typedef itk::ImageFileReader&lt; InputImageType &gt; ReaderType; // read input image as float</P>
<P>ReaderType::Pointer reader = ReaderType::New();</P>
<P></P>
<P>reader-&gt;SetFileName(inputFile); </P>
<P>writer-&gt;SetFileName( outputFile );</P>
<P><U>// Read Input Image of RAW Type (uses MetaImage Header)</U></P>
<P>try { reader-&gt;Update(); }</P>
<P>catch( itk::ExceptionObject &amp; e ) {</P>
<P>std::cerr &lt;&lt; "Exception caught during Raw file reading " &lt;&lt; std::endl;</P>
<P>std::cerr &lt;&lt; e &lt;&lt; std::endl;</P>
<P>std::cout&lt;&lt; "\n\nMake Sure if the file name you specified already exists...\n"; </P>
<P>return -1;</P>
<P>} </P>
<P></P>
<P><U>// First apply Edge Preserving smoothing filter "Anisotropic Diffusion Filter"</U></P>
<P>filter-&gt;SetInput( reader-&gt;GetOutput() ); </P>
<P>filter-&gt;SetIterations(noOfIterations); // default value -&gt; 3</P>
<P>filter-&gt;SetConductanceParameter(conductance); // default value -&gt; 5.0</P>
<P>filter-&gt;SetTimeStep(timeStep); // default value -&gt; 0.25 for 2-D image </P>
<P><U>// Pass the output of Anisotropic Diffusion Filter to GradientMagnitudeFilter</U></P>
<P>gradientFilter-&gt;SetInput( filter-&gt;GetOutput() );</P>
<P><U>// Apply Watershed Segmentation</U></P>
<P>watershed-&gt;SetInput(gradientFilter-&gt;GetOutput()); </P>
<P>watershed-&gt;SetThreshold(threshold); // 0.30</P>
<P>watershed-&gt;SetLevel(floodLevel); // 0.50 </P>
<P>writer-&gt;SetInput(watershed-&gt;GetOutput()); </P>
<P></P>
<P><U>// Execute the pipeline</U></P>
<P>try { writer-&gt;Update(); }</P>
<P>catch( itk::ExceptionObject &amp; excep ){</P>
<P>std::cerr &lt;&lt; "Exception caught !" &lt;&lt; std::endl;</P>
<P>std::cerr &lt;&lt; excep &lt;&lt; std::endl;</P>
<P>retVal = -1;</P>
<P>} </P>
<P>}</P></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>***********************************************************************************<BR><BR><B><I>Joshua Cates &lt;cates at sci.utah.edu&gt;</I></B> wrote:</DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">Hi,<BR><BR>Thanks for the feedback on the watershed example. This code is old and <BR>probably in need of updating for more recent developments in the ITK IO <BR>classes. I will take a look.<BR><BR>Josh.<BR><BR>On Mon, 23 Feb 2004, neha k wrote:<BR><BR>&gt; <BR>&gt; Hi All,<BR>&gt; <BR>&gt; I am trying to run exampleI programs in Watershed segmetnation. I tried<BR>&gt; the example program with Input file as PGM file (in.pgm) which is of<BR>&gt; size (24*7). When I run itkWatershedSegmentationExample.cxx, I get 5<BR>&gt; output files of raw format (with level = 0.50). When I set any of those<BR>&gt; 5 output files as an input file to second program itkWSRawToPNG.cxx so<BR>&gt; that I can convert it to png file to view, program crashes( on statement<BR>&gt; reader_update()). What should be the input file given to this second<BR>&gt; program? Also, if i want to segment the raw brest
 images, what reader<BR>&gt; should I use and how should i generate the output files? What filters,<BR>&gt; mappers should I use to apply watershed segmentation on grayscale breast<BR>&gt; images of Raw format to find out if there is any lesion inside the brest<BR>&gt; image? (Currently, I am using MetaImageReader to apply other ITK filters<BR>&gt; on breast images.)<BR>&gt; <BR>&gt; Any suggestions are appreiated.<BR>&gt; <BR>&gt; My input PGM file is as follows<BR>&gt; <BR>&gt; ***************************************************************************************<BR>&gt; <BR>&gt; P2<BR>&gt; <BR>&gt; 24 7<BR>&gt; <BR>&gt; 15<BR>&gt; <BR>&gt; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<BR>&gt; <BR>&gt; 0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0<BR>&gt; <BR>&gt; 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0<BR>&gt; <BR>&gt; 0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0<BR>&gt; <BR>&gt; 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0<BR>&gt; <BR>&gt; 0
 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0<BR>&gt; <BR>&gt; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; *************************************************************************************** <BR>&gt; <BR>&gt; Thanks,<BR>&gt; <BR>&gt; Neha<BR>&gt; <BR>&gt; <BR>&gt; ---------------------------------<BR>&gt; Do you Yahoo!?<BR>&gt; Yahoo! Mail SpamGuard - Read only the mail you want.<BR><BR>_______________________________________________<BR>Insight-users mailing list<BR>Insight-users at itk.org<BR>http://www.itk.org/mailman/listinfo/insight-users</BLOCKQUOTE><p><hr SIZE=1>
Do you Yahoo!?<br>
Get better spam protection with <a href="http://us.rd.yahoo.com/mailtag_us/*http://antispam.yahoo.com/tools">Yahoo! Mail</a>
--0-1803944301-1077928857=:96858--