Skip to content
Snippets Groups Projects
Commit a60e41d7 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

commentaires seam carving exemple 1

parent 7351e5fd
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,10 @@
// This example illustrates the details of the seam carving operation.
// References to this method can be found in \cite{Avidan07}. This example
// details the use of \doxygen{otb}{ImageToCarvingPathFilter} and
// \doxygen{otb}{RemoveCarvingPathFilter}.
// \doxygen{otb}{RemoveCarvingPathFilter}.
//
// In this example, a loop is defined to remove a vertical or horizontal seam
// at each step of the algorithm. The seam with the minimum energy is chosen.
//
// Software Guide : EndLatex
......@@ -67,7 +70,8 @@ int main(int argc, char ** argv)
typedef otb::ImageFileReader< ImageType > ReaderType;
typedef otb::ImageFileWriter< OutputImageType > WriterType;
typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescalerType;
typedef itk::RescaleIntensityImageFilter
<ImageType, OutputImageType> RescalerType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
......@@ -95,9 +99,9 @@ int main(int argc, char ** argv)
// Software Guide : BeginLatex
//
// The \doxygen{otb}{ImageToCarvingPathFilter} compute the path of minimum energy
// according to lines or columns of the image. Later, as we will choose the best option
// between the two, we need two of these filters.
// The \doxygen{otb}{ImageToCarvingPathFilter} compute the seam of minimum
// energy according to lines or columns of the image. Later, as we will
// choose the best option between the two, we need two of these filters.
//
// Software Guide : EndLatex
......@@ -109,20 +113,39 @@ int main(int argc, char ** argv)
// Software Guide : BeginLatex
//
// The \doxygen{otb}{RemoveCarvingPathFilter} will really resize the image deleting
// the path.
// The \doxygen{otb}{RemoveCarvingPathFilter} will really resize the image
// deleting the path.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::RemoveCarvingPathFilter
<ImageType, PathType, ImageType> RemoveCarvingPathFilterType;
RemoveCarvingPathFilterType::Pointer removeCarvingPath = RemoveCarvingPathFilterType::New();
RemoveCarvingPathFilterType::Pointer removeCarvingPath =
RemoveCarvingPathFilterType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// As we are going to iterate through the filters, we need to disconnect the
// pipeline at one point and store the image somewhere. For that purpose, we
// use an \doxygen{itk}{ImageDuplicator}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::ImageDuplicator< ImageType > duplicatorType;
duplicatorType::Pointer duplicator = duplicatorType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Now that all elements have been instanciated, we start to plug the pipeline
// and to define the loop.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
reader->Update();
duplicator->SetInputImage(reader->GetOutput());
duplicator->Update();
......@@ -135,7 +158,19 @@ int main(int argc, char ** argv)
gradient->SetInput( duplicator->GetOutput() );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Two carving filters processed the gradient image to find the minimum
// vertical seam and the minimum horizontal seam. Note that the
// \code{UpdateLargestPossibleRegion()} need to be used as the size of the
// input image will be different in each loop.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
carvingFilterVert->SetInput( gradient->GetOutput() );
carvingFilterVert->SetDirection(0);
carvingFilterVert->UpdateLargestPossibleRegion();
......@@ -145,7 +180,16 @@ int main(int argc, char ** argv)
carvingFilterHor->SetDirection(1);
carvingFilterHor->UpdateLargestPossibleRegion();
energyHor = carvingFilterHor->GetEnergyPerPix();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The vertical or the horizontal seam with the minimal energy is chosen.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
if (energyVert < energyHor)
{
removeCarvingPath->SetInput( duplicator->GetOutput() );
......@@ -160,17 +204,32 @@ int main(int argc, char ** argv)
removeCarvingPath->SetDirection(1);
removeCarvingPath->UpdateLargestPossibleRegion();
}
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The duplicator filter keep the results for the next loop
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
duplicator->SetInputImage(removeCarvingPath->GetOutput());
duplicator->Update();
}
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Finally, the resulting image is saved on an image file as usual
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
rescaler->SetInput( duplicator->GetOutput() );
writer->SetInput( rescaler->GetOutput() );
writer->Update();
// Software Guide : EndCodeSnippet
return EXIT_SUCCESS;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment