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
Julien Cabieces
otb
Commits
32e67e4d
Commit
32e67e4d
authored
17 years ago
by
Cyrille Valladeau
Browse files
Options
Downloads
Patches
Plain Diff
SVMTaylor Classif + KMeans streame.
parent
56edf642
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Common/otbGenericInterpolateImageFunction.txx
+5
-2
5 additions, 2 deletions
Code/Common/otbGenericInterpolateImageFunction.txx
Testing/Code/Learning/otbSVMClassifierImage.cxx
+63
-92
63 additions, 92 deletions
Testing/Code/Learning/otbSVMClassifierImage.cxx
with
68 additions
and
94 deletions
Code/Common/otbGenericInterpolateImageFunction.txx
+
5
−
2
View file @
32e67e4d
...
...
@@ -238,8 +238,11 @@ GenericInterpolateImageFunction<TInputImage, TFunction, TBoundaryCondition, TCoo
/* double xWeight[ImageDimension][ twiceRadius];*/
std::vector< std::vector<double> > xWeight;
xWeight.resize(ImageDimension);
for(int cpt=0 ;cpt <xWeight.size() ; cpt++) xWeight[cpt].resize(twiceRadius);
for(unsigned int cpt=0; cpt < xWeight.size(); cpt++)
{
xWeight[cpt].resize(twiceRadius);
}
for( unsigned int dim = 0; dim < ImageDimension; dim++ )
{
// x is the offset, hence the parameter of the kernel
...
...
This diff is collapsed.
Click to expand it.
Testing/Code/Learning/otbSVMClassifierImage.cxx
+
63
−
92
View file @
32e67e4d
...
...
@@ -62,89 +62,73 @@ public:
int
otbSVMClassifierImage
(
int
argc
,
char
*
argv
[]
)
{
try
namespace
stat
=
itk
::
Statistics
;
if
(
argc
!=
4
)
{
namespace
stat
=
itk
::
Statistics
;
if
(
argc
!=
4
)
{
std
::
cout
<<
"Usage : "
<<
argv
[
0
]
<<
" inputImage modelFile outputImage"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
const
char
*
imageFilename
=
argv
[
1
];
const
char
*
modelFilename
=
argv
[
2
];
const
char
*
outputFilename
=
argv
[
3
];
/** Read the input image and build the sample */
typedef
double
InputPixelType
;
typedef
std
::
vector
<
InputPixelType
>
InputVectorType
;
typedef
int
LabelPixelType
;
const
unsigned
int
Dimension
=
2
;
typedef
otb
::
Image
<
itk
::
FixedArray
<
InputPixelType
,
3
>
,
Dimension
>
InputImageType
;
typedef
otb
::
ImageFileReader
<
InputImageType
>
ReaderType
;
ReaderType
::
Pointer
reader
=
ReaderType
::
New
();
reader
->
SetFileName
(
imageFilename
);
reader
->
Update
();
std
::
cout
<<
"Image read"
<<
std
::
endl
;
typedef
itk
::
Statistics
::
ImageToListAdaptor
<
InputImageType
>
SampleType
;
SampleType
::
Pointer
sample
=
SampleType
::
New
();
sample
->
SetImage
(
reader
->
GetOutput
());
/** preparing classifier and decision rule object */
typedef
otb
::
SVMModel
<
InputPixelType
,
LabelPixelType
>
ModelType
;
ModelType
::
Pointer
model
=
ModelType
::
New
();
otb
::
Linear
lFunctor
;
model
->
SetKernelFunctor
(
&
lFunctor
);
model
->
LoadModel
(
modelFilename
);
int
numberOfClasses
=
model
->
GetNumberOfClasses
();
}
const
char
*
imageFilename
=
argv
[
1
];
const
char
*
modelFilename
=
argv
[
2
];
const
char
*
outputFilename
=
argv
[
3
];
/** Read the input image and build the sample */
typedef
double
InputPixelType
;
typedef
std
::
vector
<
InputPixelType
>
InputVectorType
;
typedef
int
LabelPixelType
;
const
unsigned
int
Dimension
=
2
;
typedef
otb
::
Image
<
itk
::
FixedArray
<
InputPixelType
,
3
>
,
Dimension
>
InputImageType
;
typedef
otb
::
ImageFileReader
<
InputImageType
>
ReaderType
;
ReaderType
::
Pointer
reader
=
ReaderType
::
New
();
reader
->
SetFileName
(
imageFilename
);
reader
->
Update
();
typedef
itk
::
Statistics
::
ImageToListAdaptor
<
InputImageType
>
SampleType
;
SampleType
::
Pointer
sample
=
SampleType
::
New
();
sample
->
SetImage
(
reader
->
GetOutput
());
/** preparing classifier and decision rule object */
typedef
otb
::
SVMModel
<
InputPixelType
,
LabelPixelType
>
ModelType
;
ModelType
::
Pointer
model
=
ModelType
::
New
();
typedef
otb
::
SVMClassifier
<
SampleType
,
LabelPixelType
>
ClassifierType
;
ClassifierType
::
Pointer
classifier
=
ClassifierType
::
New
()
;
otb
::
Linear
lFunctor
;
model
->
SetKernelFunctor
(
&
lFunctor
);
classifier
->
SetNumberOfClasses
(
numberOfClasses
)
;
classifier
->
SetModel
(
model
);
classifier
->
SetSample
(
sample
.
GetPointer
())
;
classifier
->
Update
()
;
/* Build the class map */
std
::
cout
<<
"Output image creation"
<<
std
::
endl
;
typedef
ClassifierType
::
ClassLabelType
OutputPixelType
;
typedef
otb
::
Image
<
OutputPixelType
,
Dimension
>
OutputImageType
;
model
->
LoadModel
(
modelFilename
);
int
numberOfClasses
=
model
->
GetNumberOfClasses
();
typedef
otb
::
SVMClassifier
<
SampleType
,
LabelPixelType
>
ClassifierType
;
ClassifierType
::
Pointer
classifier
=
ClassifierType
::
New
()
;
classifier
->
SetNumberOfClasses
(
numberOfClasses
)
;
classifier
->
SetModel
(
model
);
classifier
->
SetSample
(
sample
.
GetPointer
())
;
classifier
->
Update
()
;
/* Build the class map */
itkGenericExceptionMacro
(
<<
"Output image creation"
);
typedef
ClassifierType
::
ClassLabelType
OutputPixelType
;
typedef
otb
::
Image
<
OutputPixelType
,
Dimension
>
OutputImageType
;
OutputImageType
::
Pointer
outputImage
=
OutputImageType
::
New
();
typedef
itk
::
Index
<
Dimension
>
myIndexType
;
typedef
itk
::
Size
<
Dimension
>
mySizeType
;
typedef
itk
::
ImageRegion
<
Dimension
>
myRegionType
;
typedef
itk
::
ImageRegion
<
Dimension
>
myRegionType
;
mySizeType
size
;
size
[
0
]
=
reader
->
GetOutput
()
->
GetRequestedRegion
().
GetSize
()[
0
];
...
...
@@ -162,16 +146,16 @@ int otbSVMClassifierImage(int argc, char* argv[] )
outputImage
->
Allocate
();
std
::
cout
<<
"classifier get output"
<<
std
::
endl
;
itkGenericExceptionMacro
(
<<
"classifier get output"
)
;
ClassifierType
::
OutputType
*
membershipSample
=
classifier
->
GetOutput
()
;
std
::
cout
<<
"Sample iterators"
<<
std
::
endl
;
itkGenericExceptionMacro
(
<<
"Sample iterators"
)
;
ClassifierType
::
OutputType
::
ConstIterator
m_iter
=
membershipSample
->
Begin
()
;
ClassifierType
::
OutputType
::
ConstIterator
m_last
=
membershipSample
->
End
()
;
std
::
cout
<<
"Image iterator"
<<
std
::
endl
;
itkGenericExceptionMacro
(
<<
"Image iterator"
)
;
typedef
itk
::
ImageRegionIterator
<
OutputImageType
>
OutputIteratorType
;
OutputIteratorType
outIt
(
outputImage
,
outputImage
->
GetBufferedRegion
()
);
...
...
@@ -179,13 +163,13 @@ int otbSVMClassifierImage(int argc, char* argv[] )
outIt
.
GoToBegin
();
std
::
cout
<<
"Iteration for output image = "
<<
(
membershipSample
->
Size
())
<<
std
::
endl
;
itkGenericExceptionMacro
(
<<
"Iteration for output image = "
<<
(
membershipSample
->
Size
())
)
;
while
(
m_iter
!=
m_last
&&
!
outIt
.
IsAtEnd
())
{
outIt
.
Set
(
m_iter
.
GetClassLabel
());
++
m_iter
;
++
outIt
;
outIt
.
Set
(
m_iter
.
GetClassLabel
());
++
m_iter
;
++
outIt
;
}
...
...
@@ -211,21 +195,8 @@ int otbSVMClassifierImage(int argc, char* argv[] )
writer
->
Update
();
}
catch
(
itk
::
ExceptionObject
&
err
)
{
std
::
cout
<<
"Exception itk::ExceptionObject levee !"
<<
std
::
endl
;
std
::
cout
<<
err
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
catch
(
...
)
{
std
::
cout
<<
"Unknown exception !"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
return
EXIT_SUCCESS
;
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