Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Youssefi
otb
Commits
a60e41d7
Commit
a60e41d7
authored
17 years ago
by
Emmanuel Christophe
Browse files
Options
Downloads
Patches
Plain Diff
commentaires seam carving exemple 1
parent
7351e5fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Examples/FeatureExtraction/SeamCarvingExample.cxx
+68
-9
68 additions, 9 deletions
Examples/FeatureExtraction/SeamCarvingExample.cxx
with
68 additions
and
9 deletions
Examples/FeatureExtraction/SeamCarvingExample.cxx
+
68
−
9
View file @
a60e41d7
...
...
@@ -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
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment