int main(
int argc,
char * argv[])
{
const unsigned int Dimension = 2;
typedef double PixelType;
typedef unsigned char OutputPixelType;
MultispectralReaderType::Pointer multispectralReader =
MultispectralReaderType::New();
multispectralReader->SetFileName(argv[1]);
<MultiSpectralImageType, OutputVectorImageType> VectorRescalerType;
unsigned char> ChannelExtractorType;
OutputVectorImageType::PixelType minimum, maximum;
minimum.SetSize(
multispectralReader->GetOutput()->GetNumberOfComponentsPerPixel());
maximum.SetSize(
multispectralReader->GetOutput()->GetNumberOfComponentsPerPixel());
minimum.Fill(0);
maximum.Fill(255);
VectorRescalerType::Pointer vr = VectorRescalerType::New();
vr->SetInput(multispectralReader->GetOutput());
vr->SetOutputMinimum(minimum);
vr->SetOutputMaximum(maximum);
vr->SetClampThreshold(0.01);
ChannelExtractorType::Pointer selecter = ChannelExtractorType::New();
selecter->SetInput(vr->GetOutput());
selecter->SetExtractionRegion(
multispectralReader->GetOutput()->GetLargestPossibleRegion());
selecter->SetChannel(3);
selecter->SetChannel(2);
selecter->SetChannel(1);
VectorWriterType::Pointer vectWriter = VectorWriterType::New();
vectWriter->SetFileName(argv[3]);
vectWriter->SetInput(selecter->GetOutput());
vectWriter->Update();
MultiSpectralImageType::PixelType pixelRef;
pixelRef.SetSize(4);
pixelRef[0] = atoi(argv[4]);
pixelRef[1] = atoi(argv[5]);
pixelRef[2] = atoi(argv[6]);
pixelRef[3] = atoi(argv[7]);
double resolution = 0.6;
double alpha = atof(argv[9]);
InternalImageType> SAFilterType;
SAFilterType::Pointer saFilter = SAFilterType::New();
saFilter->SetReferencePixel(pixelRef);
saFilter->SetInput(multispectralReader->GetOutput());
InternalImageType> SqrtFilterType;
SqrtFilterType::Pointer sqrtFilter = SqrtFilterType::New();
sqrtFilter->SetInput(saFilter->GetOutput());
double sigma = alpha * (1.2 / resolution + 1);
VectorImageType>
GradientFilterType;
GradientFilterType::Pointer gradientFilter = GradientFilterType::New();
gradientFilter->SetSigma(sigma);
gradientFilter->SetInput(sqrtFilter->GetOutput());
InternalImageType,
InternalImageType>
NeighborhoodScalarProductType;
NeighborhoodScalarProductType::Pointer scalarFilter
= NeighborhoodScalarProductType::New();
scalarFilter->SetInput(gradientFilter->GetOutput());
InternalImageType,
InternalImageType>
RemoveIsolatedByDirectionType;
RemoveIsolatedByDirectionType::Pointer removeIsolatedByDirectionFilter
= RemoveIsolatedByDirectionType::New();
removeIsolatedByDirectionFilter->SetInput(scalarFilter->GetOutput());
removeIsolatedByDirectionFilter
->SetInputDirection(scalarFilter->GetOutputDirection());
InternalImageType,
InternalImageType>
RemoveWrongDirectionType;
RemoveWrongDirectionType::Pointer removeWrongDirectionFilter
= RemoveWrongDirectionType::New();
removeWrongDirectionFilter->SetInput(
removeIsolatedByDirectionFilter->GetOutput());
removeWrongDirectionFilter->SetInputDirection(
scalarFilter->GetOutputDirection());
InternalImageType,
InternalImageType>
NonMaxRemovalByDirectionType;
NonMaxRemovalByDirectionType::Pointer nonMaxRemovalByDirectionFilter
= NonMaxRemovalByDirectionType::New();
nonMaxRemovalByDirectionFilter->SetInput(
removeWrongDirectionFilter->GetOutput());
nonMaxRemovalByDirectionFilter
->SetInputDirection(scalarFilter->GetOutputDirection());
InternalImageType,
PathType> VectorizationFilterType;
VectorizationFilterType::Pointer vectorizationFilter
= VectorizationFilterType::New();
vectorizationFilter->SetInput(nonMaxRemovalByDirectionFilter->GetOutput());
vectorizationFilter->SetInputDirection(scalarFilter->GetOutputDirection());
vectorizationFilter->SetAmplitudeThreshold(atof(argv[8]));
SimplifyPathType::Pointer simplifyPathListFilter = SimplifyPathType::New();
simplifyPathListFilter->GetFunctor().SetTolerance(1.0);
simplifyPathListFilter->SetInput(vectorizationFilter->GetOutput());
BreakAngularPathType::Pointer breakAngularPathListFilter
= BreakAngularPathType::New();
breakAngularPathListFilter->SetInput(simplifyPathListFilter->GetOutput());
RemoveTortuousPathType::Pointer removeTortuousPathListFilter
= RemoveTortuousPathType::New();
removeTortuousPathListFilter->GetFunctor().SetThreshold(1.0);
removeTortuousPathListFilter->SetInput(breakAngularPathListFilter->GetOutput());
LinkPathType::Pointer linkPathListFilter = LinkPathType::New();
linkPathListFilter->SetDistanceThreshold(25.0 / resolution);
linkPathListFilter->SetInput(removeTortuousPathListFilter->GetOutput());
SimplifyPathType::Pointer simplifyPathListFilter2 = SimplifyPathType::New();
simplifyPathListFilter2->GetFunctor().SetTolerance(1.0);
simplifyPathListFilter2->SetInput(linkPathListFilter->GetOutput());
RemoveTortuousPathType::Pointer removeTortuousPathListFilter2
= RemoveTortuousPathType::New();
removeTortuousPathListFilter2->GetFunctor().SetThreshold(10.0);
removeTortuousPathListFilter2->SetInput(simplifyPathListFilter2->GetOutput());
InternalImageType>
PathListToPathListWithValueType;
PathListToPathListWithValueType::Pointer pathListConverter
= PathListToPathListWithValueType::New();
pathListConverter->SetInput(removeTortuousPathListFilter2->GetOutput());
pathListConverter->SetInputImage(nonMaxRemovalByDirectionFilter->GetOutput());
InternalImageType::Pointer output = InternalImageType::New();
output->SetRegions(multispectralReader->GetOutput()
->GetLargestPossibleRegion());
output->Allocate();
output->FillBuffer(0.0);
InternalImageType> DrawPathType;
DrawPathType::Pointer drawPathListFilter = DrawPathType::New();
drawPathListFilter->SetInput(output);
drawPathListFilter->SetInputPath(pathListConverter->GetOutput());
drawPathListFilter->SetUseInternalPathValue(true);
InternalImageType> RescalerType;
RescalerType::Pointer rescaler = RescalerType::New();
rescaler->SetOutputMaximum(255);
rescaler->SetOutputMinimum(0);
rescaler->SetInput(drawPathListFilter->GetOutput());
rescaler->Update();
PixelType>
ChannelExtractionFilterType;
InternalImageType> AddFilterType;
InternalImageType> SubtractFilterType;
ThresholdFilterType;
RGBPixelType;
Dimension> RGBImageType;
RGBImageType> ComposeRGBFilterType;
RGBWriterType;
Dimension> StructuringElementType;
<InternalImageType, InternalImageType,
StructuringElementType> DilateFilterType;
StructuringElementType se;
se.CreateStructuringElement();
ChannelExtractionFilterType::Pointer channelExtractor1 =
ChannelExtractionFilterType::New();
ChannelExtractionFilterType::Pointer channelExtractor2 =
ChannelExtractionFilterType::New();
ChannelExtractionFilterType::Pointer channelExtractor3 =
ChannelExtractionFilterType::New();
AddFilterType::Pointer addFilter = AddFilterType::New();
SubtractFilterType::Pointer subtract2 = SubtractFilterType::New();
SubtractFilterType::Pointer subtract3 = SubtractFilterType::New();
ThresholdFilterType::Pointer threshold11 = ThresholdFilterType::New();
ThresholdFilterType::Pointer threshold21 = ThresholdFilterType::New();
ThresholdFilterType::Pointer threshold31 = ThresholdFilterType::New();
ThresholdFilterType::Pointer threshold12 = ThresholdFilterType::New();
ThresholdFilterType::Pointer threshold22 = ThresholdFilterType::New();
ThresholdFilterType::Pointer threshold32 = ThresholdFilterType::New();
ComposeRGBFilterType::Pointer composer = ComposeRGBFilterType::New();
RGBWriterType::Pointer writer = RGBWriterType::New();
DilateFilterType::Pointer dilater = DilateFilterType::New();
dilater->SetInput(rescaler->GetOutput());
dilater->SetKernel(se);
channelExtractor1->SetInput(vr->GetOutput());
channelExtractor2->SetInput(vr->GetOutput());
channelExtractor3->SetInput(vr->GetOutput());
channelExtractor1->SetChannel(3);
channelExtractor2->SetChannel(2);
channelExtractor3->SetChannel(1);
addFilter->SetInput1(channelExtractor1->GetOutput());
addFilter->SetInput2(dilater->GetOutput());
subtract2->SetInput1(channelExtractor2->GetOutput());
subtract2->SetInput2(dilater->GetOutput());
subtract3->SetInput1(channelExtractor3->GetOutput());
subtract3->SetInput2(dilater->GetOutput());
threshold11->SetInput(addFilter->GetOutput());
threshold11->ThresholdBelow(0);
threshold11->SetOutsideValue(0);
threshold12->SetInput(threshold11->GetOutput());
threshold12->ThresholdAbove(255);
threshold12->SetOutsideValue(255);
threshold21->SetInput(subtract2->GetOutput());
threshold21->ThresholdBelow(0);
threshold21->SetOutsideValue(0);
threshold22->SetInput(threshold21->GetOutput());
threshold22->ThresholdAbove(255);
threshold22->SetOutsideValue(255);
threshold31->SetInput(subtract3->GetOutput());
threshold31->ThresholdBelow(0);
threshold31->SetOutsideValue(0);
threshold32->SetInput(threshold31->GetOutput());
threshold32->ThresholdAbove(255);
threshold32->SetOutsideValue(255);
composer->SetInput1(threshold12->GetOutput());
composer->SetInput2(threshold22->GetOutput());
composer->SetInput3(threshold32->GetOutput());
writer->SetInput(composer->GetOutput());
writer->SetFileName(argv[2]);
writer->Update();
return EXIT_SUCCESS;
}