<div class="gmail_quote">On Fri, Apr 8, 2011 at 10:32 AM, john smith <span dir="ltr"><<a href="mailto:mkitkinsightuser@gmail.com">mkitkinsightuser@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello,<br> I have the followin code from itk-manual to run OtsuMultipleThresholdImageFilter. What must I type in the command window to run the project?<br>Thanks in advance<br><br>//////////// code//////////////<br><br><br>
#include "itkOtsuMultipleThresholdsCalculator.h"<br><br><br>#include "itkImage.h"<br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "itkScalarImageToHistogramGenerator.h"<br>
#include "itkBinaryThresholdImageFilter.h"<br>#include "itkNumericTraits.h"<br><br>#include <stdio.h><br>int main( int argc, char * argv[] )<br>{<br> if( argc < 5 )<br> {<br> std::cerr << "Usage: " << argv[0];<br>
std::cerr << " inputImageFile outputImageFileBase "; <br> std::cerr << " outputImageFileExtension numberOfThresholdsToCalculate " << std::endl; <br> return EXIT_FAILURE;<br>
}<br> <br><br> typedef unsigned short InputPixelType;<br> typedef unsigned char OutputPixelType;<br> <br> typedef itk::Image< InputPixelType, 3 > InputImageType;<br> typedef itk::Image< OutputPixelType, 3 > OutputImageType;<br>
<br><br> typedef itk::Statistics::ScalarImageToHistogramGenerator< <br> InputImageType > <br> ScalarImageToHistogramGeneratorType;<br><br> typedef ScalarImageToHistogramGeneratorType::HistogramType HistogramType;<br>
<br> typedef itk::OtsuMultipleThresholdsCalculator< HistogramType > CalculatorType;<br><br><br> typedef itk::ImageFileReader< InputImageType > ReaderType;<br> typedef itk::ImageFileWriter< OutputImageType > WriterType;<br>
<br><br> typedef itk::BinaryThresholdImageFilter< <br> InputImageType, OutputImageType > FilterType;<br><br> ScalarImageToHistogramGeneratorType::Pointer scalarImageToHistogramGenerator = <br> ScalarImageToHistogramGeneratorType::New();<br>
<br> CalculatorType::Pointer calculator = CalculatorType::New();<br> FilterType::Pointer filter = FilterType::New();<br><br><br> ReaderType::Pointer reader = ReaderType::New();<br> WriterType::Pointer writer = WriterType::New();<br>
<br><br> scalarImageToHistogramGenerator->SetNumberOfBins( 128 );<br> calculator->SetNumberOfThresholds( atoi( argv[4] ) );<br><br> const OutputPixelType outsideValue = 0;<br> const OutputPixelType insideValue = 255;<br>
<br> filter->SetOutsideValue( outsideValue );<br> filter->SetInsideValue( insideValue );<br><br><br> reader->SetFileName( argv[1] );<br><br> <br> scalarImageToHistogramGenerator->SetInput( reader->GetOutput() );<br>
calculator->SetInputHistogram( scalarImageToHistogramGenerator->GetOutput() );<br> filter->SetInput( reader->GetOutput() );<br> writer->SetInput( filter->GetOutput() );<br> <br> try<br> { <br> reader->Update();<br>
}<br> catch( itk::ExceptionObject & excp )<br> {<br> std::cerr << "Exception thrown while reading image" << excp << std::endl;<br> }<br> scalarImageToHistogramGenerator->Compute();<br>
<br> try<br> { <br> calculator->Update();<br> }<br> catch( itk::ExceptionObject & excp )<br> {<br> std::cerr << "Exception thrown " << excp << std::endl;<br> }<br>
<br>
<br> const CalculatorType::OutputType &thresholdVector = calculator->GetOutput(); <br> CalculatorType::OutputType::const_iterator itNum = thresholdVector.begin();<br> <br><span style="background-color:rgb(255, 255, 51)"> std::string outputFileBase = argv[2];</span><br>
std::string outputFile;<br> <br> InputPixelType lowerThreshold = 0;<br> InputPixelType upperThreshold;<br><br style="background-color:rgb(255, 255, 51)"><span style="background-color:rgb(255, 255, 51)"> std::string format = argv[2];</span><br>
<br> char outputFilename[1000];<br> outputFile = outputFileBase + "%03d.";<br> <span style="background-color:rgb(255, 255, 51)">outputFile += argv[3]; // filename extension</span><br><br> <br>
for(; itNum < thresholdVector.end(); itNum++) <br> {<br> std::cout << "OtsuThreshold["<br> << (int)(itNum - thresholdVector.begin())<br> << "] = " <br>
<< static_cast<itk::NumericTraits<CalculatorType::MeasurementType>::PrintType>(*itNum) <br> << std::endl; <br><br> <br> upperThreshold = static_cast<InputPixelType>(*itNum);<br>
<br> filter->SetLowerThreshold( lowerThreshold );<br> filter->SetUpperThreshold( upperThreshold );<br><br> lowerThreshold = upperThreshold;<br><br> sprintf (outputFilename, outputFile.c_str(), (itNum - thresholdVector.begin()));<br>
writer->SetFileName( outputFilename );<br> <br><br> try<br> { <br> writer->Update(); <br> }<br> catch( itk::ExceptionObject & excp )<br> {<br> std::cerr << "Exception thrown " << excp << std::endl;<br>
}<br> <br> }<br><br> upperThreshold = itk::NumericTraits<InputPixelType>::max();<br> filter->SetLowerThreshold( lowerThreshold );<br> filter->SetUpperThreshold( upperThreshold );<br> <br> sprintf (outputFilename, outputFile.c_str(), (thresholdVector.size() ));<br>
writer->SetFileName( outputFilename );<br> <br> try<br> { <br> writer->Update(); <br> }<br> catch( itk::ExceptionObject & excp )<br> {<br> std::cerr << "Exception thrown " << excp << std::endl;<br>
}<br><br><br> return EXIT_SUCCESS;<br>}<br><br></blockquote><div><br></div><div>At the top of the example there is an explanation:</div><div><br></div><div>// INPUTS: {BrainProtonDensitySlice.png}</div><div>// OtsuMultipleThresholdsOutput png 4 </div>
<div><br></div><div>I would guess that this would translate to :</div><div><br></div><div>./ThisProgram BrainProtonDensitySlice.png OtsuMultipleThresholdsOutput png 4 </div><div><br></div><div>I'm not sure why INPUTS{} is in brackets, etc.</div>
<div><br></div><div>David</div><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div></div></div>