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
fe0c1fa0
Commit
fe0c1fa0
authored
13 years ago
by
Manuel Grizonnet
Browse files
Options
Downloads
Patches
Plain Diff
ENH:improve output informations of ReadImageInfo application
parent
57741ba5
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
Applications/Utils/otbReadImageInfo.cxx
+162
-77
162 additions, 77 deletions
Applications/Utils/otbReadImageInfo.cxx
with
162 additions
and
77 deletions
Applications/Utils/otbReadImageInfo.cxx
+
162
−
77
View file @
fe0c1fa0
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
#include
"otbWrapperApplication.h"
#include
"otbWrapperApplication.h"
#include
"otbWrapperApplicationFactory.h"
#include
"otbWrapperApplicationFactory.h"
#include
"otbCoordinateToName.h"
#include
"otbCoordinateToName.h"
#include
"otbGroundSpacingImageFunction.h"
#include
"vnl/vnl_random.h"
namespace
otb
namespace
otb
{
{
...
@@ -33,6 +35,10 @@ public:
...
@@ -33,6 +35,10 @@ public:
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
typedef
otb
::
GroundSpacingImageFunction
<
FloatVectorImageType
>
GroundSpacingImageType
;
typedef
typename
GroundSpacingImageType
::
FloatType
FloatType
;
typedef
typename
GroundSpacingImageType
::
ValueType
ValueType
;
/** Standard macro */
/** Standard macro */
itkNewMacro
(
Self
);
itkNewMacro
(
Self
);
...
@@ -70,6 +76,12 @@ private:
...
@@ -70,6 +76,12 @@ private:
SetParameterRole
(
"spacingx"
,
Role_Output
);
SetParameterRole
(
"spacingx"
,
Role_Output
);
AddParameter
(
ParameterType_Int
,
"spacingy"
,
"Pixel Size Y"
);
AddParameter
(
ParameterType_Int
,
"spacingy"
,
"Pixel Size Y"
);
SetParameterRole
(
"spacingy"
,
Role_Output
);
SetParameterRole
(
"spacingy"
,
Role_Output
);
AddParameter
(
ParameterType_Float
,
"estimatedgroundspacingx"
,
"Estimated ground spacing X (in meters)"
);
SetParameterRole
(
"estimatedgroundspacingx"
,
Role_Output
);
AddParameter
(
ParameterType_Float
,
"estimatedgroundspacingy"
,
"Estimated ground spacing Y (in meters)"
);
SetParameterRole
(
"estimatedgroundspacingy"
,
Role_Output
);
AddParameter
(
ParameterType_Int
,
"numberbands"
,
"Number Of Bands"
);
AddParameter
(
ParameterType_Int
,
"numberbands"
,
"Number Of Bands"
);
SetParameterRole
(
"numberbands"
,
Role_Output
);
SetParameterRole
(
"numberbands"
,
Role_Output
);
...
@@ -177,28 +189,73 @@ private:
...
@@ -177,28 +189,73 @@ private:
void
DoExecute
()
void
DoExecute
()
{
{
try
std
::
ostringstream
ossOutput
;
{
FloatVectorImageType
::
Pointer
inImage
=
GetParameterImage
(
"in"
);
FloatVectorImageType
::
Pointer
inImage
=
GetParameterImage
(
"in"
);
// Read informations
ossOutput
<<
std
::
endl
<<
"Image general informations:"
<<
std
::
endl
;
typedef
otb
::
ImageMetadataInterfaceBase
ImageMetadataInterfaceType
;
// Read informations
ImageMetadataInterfaceType
::
Pointer
metadataInterface
=
ImageMetadataInterfaceFactory
::
CreateIMI
(
inImage
->
GetMetaDataDictionary
());
typedef
otb
::
ImageMetadataInterfaceBase
ImageMetadataInterfaceType
;
ImageMetadataInterfaceType
::
Pointer
metadataInterface
=
ImageMetadataInterfaceFactory
::
CreateIMI
(
inImage
->
GetMetaDataDictionary
());
//Get image size
SetParameterInt
(
"sizex"
,
inImage
->
GetLargestPossibleRegion
().
GetSize
()[
0
]);
//Get number of bands
SetParameterInt
(
"sizey"
,
inImage
->
GetLargestPossibleRegion
().
GetSize
()[
1
]);
SetParameterInt
(
"numberbands"
,
inImage
->
GetNumberOfComponentsPerPixel
());
ossOutput
<<
"
\t
Number of bands : "
<<
GetParameterInt
(
"numberbands"
)
<<
std
::
endl
;
//Get image spacing
SetParameterInt
(
"spacingx"
,
inImage
->
GetSpacing
()[
0
]);
//Get image size
SetParameterInt
(
"spacingy"
,
inImage
->
GetSpacing
()[
1
]);
SetParameterInt
(
"sizex"
,
inImage
->
GetLargestPossibleRegion
().
GetSize
()[
0
]);
SetParameterInt
(
"sizey"
,
inImage
->
GetLargestPossibleRegion
().
GetSize
()[
1
]);
SetParameterInt
(
"numberbands"
,
inImage
->
GetNumberOfComponentsPerPixel
());
ossOutput
<<
"
\t
Size : ["
<<
GetParameterInt
(
"sizex"
)
<<
","
<<
GetParameterInt
(
"sizey"
)
<<
"]"
<<
std
::
endl
;
//Get image spacing
SetParameterInt
(
"spacingx"
,
inImage
->
GetSpacing
()[
0
]);
SetParameterInt
(
"spacingy"
,
inImage
->
GetSpacing
()[
1
]);
ossOutput
<<
"
\t
Spacing : ["
<<
GetParameterInt
(
"spacingx"
)
<<
","
<<
GetParameterInt
(
"spacingy"
)
<<
"]"
<<
std
::
endl
;
//Estimate ground spacing
GroundSpacingImageType
::
Pointer
groundSpacing
=
GroundSpacingImageType
::
New
();
groundSpacing
->
SetInputImage
(
inImage
);
FloatType
approxGroundSpacing
=
std
::
make_pair
(
itk
::
NumericTraits
<
ValueType
>::
Zero
,
itk
::
NumericTraits
<
ValueType
>::
min
());
FloatVectorImageType
::
IndexType
index
;
vnl_random
rand
;
SetParameterString
(
"sensor"
,
metadataInterface
->
GetSensorID
());
index
[
0
]
=
static_cast
<
FloatVectorImageType
::
IndexType
::
IndexValueType
>
(
rand
.
lrand32
(
0
,
inImage
->
GetLargestPossibleRegion
().
GetSize
()[
0
]));
index
[
1
]
=
static_cast
<
FloatVectorImageType
::
IndexType
::
IndexValueType
>
(
rand
.
lrand32
(
0
,
inImage
->
GetLargestPossibleRegion
().
GetSize
()[
1
]));
approxGroundSpacing
=
groundSpacing
->
EvaluateAtIndex
(
index
);
//Get image estimated ground spacing (in m)
SetParameterFloat
(
"estimatedgroundspacingx"
,
approxGroundSpacing
.
first
);
SetParameterFloat
(
"estimatedgroundspacingy"
,
approxGroundSpacing
.
second
);
ossOutput
<<
"
\t
Estimated ground spacing (in meters): ["
<<
GetParameterFloat
(
"estimatedgroundspacingx"
)
<<
","
<<
GetParameterFloat
(
"estimatedgroundspacingy"
)
<<
"]"
<<
std
::
endl
;
ossOutput
<<
std
::
endl
<<
"Image acquisition informations:"
<<
std
::
endl
;
SetParameterString
(
"sensor"
,
metadataInterface
->
GetSensorID
());
ossOutput
<<
"
\t
Sensor : "
;
if
(
!
GetParameterString
(
"sensor"
).
empty
())
ossOutput
<<
GetParameterString
(
"sensor"
);
ossOutput
<<
std
::
endl
;
ossOutput
<<
"
\t
Image identification number: "
;
if
(
metadataInterface
->
GetImageKeywordlist
().
HasKey
(
"image_id"
))
{
SetParameterString
(
"id"
,
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"image_id"
));
SetParameterString
(
"id"
,
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"image_id"
));
SetParameterString
(
"projectionref"
,
metadataInterface
->
GetProjectionRef
());
ossOutput
<<
GetParameterString
(
"id"
);
}
ossOutput
<<
std
::
endl
;
SetParameterString
(
"projectionref"
,
metadataInterface
->
GetProjectionRef
());
if
(
!
GetParameterString
(
"projectionref"
).
empty
())
ossOutput
<<
"
\t
Image projection : "
<<
GetParameterString
(
"projectionref"
)
<<
std
::
endl
;
// Format acquisition time
// Format acquisition time
//Test if this information is available and silently catch
//associated exception
try
{
std
::
ostringstream
osstime
;
std
::
ostringstream
osstime
;
osstime
<<
metadataInterface
->
GetYear
()
<<
"-"
;
osstime
<<
metadataInterface
->
GetYear
()
<<
"-"
;
if
(
metadataInterface
->
GetMonth
()
<
10
)
if
(
metadataInterface
->
GetMonth
()
<
10
)
...
@@ -215,13 +272,15 @@ private:
...
@@ -215,13 +272,15 @@ private:
osstime
<<
metadataInterface
->
GetMinute
();
osstime
<<
metadataInterface
->
GetMinute
();
osstime
<<
":00"
;
osstime
<<
":00"
;
SetParameterString
(
"time"
,
osstime
.
str
());
SetParameterString
(
"time"
,
osstime
.
str
());
ossOutput
<<
"
\t
Acquisition time : "
<<
GetParameterString
(
"time"
)
<<
std
::
endl
;
}
catch
(
itk
::
ExceptionObject
&
err
)
{
}
if
(
IsParameterEnabled
(
"keywordlist"
)
)
try
{
{
std
::
ostringstream
osskeywordlist
;
osskeywordlist
<<
metadataInterface
->
GetImageKeywordlist
()
<<
std
::
endl
;
SetParameterString
(
"keyword"
,
osskeywordlist
.
str
());
}
double
ullat
=
atof
(
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"ul_lat"
).
c_str
());
double
ullat
=
atof
(
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"ul_lat"
).
c_str
());
double
ullon
=
atof
(
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"ul_lon"
).
c_str
());
double
ullon
=
atof
(
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"ul_lon"
).
c_str
());
double
urlat
=
atof
(
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"ur_lat"
).
c_str
());
double
urlat
=
atof
(
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"ur_lat"
).
c_str
());
...
@@ -231,45 +290,6 @@ private:
...
@@ -231,45 +290,6 @@ private:
double
lllat
=
atof
(
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"ll_lat"
).
c_str
());
double
lllat
=
atof
(
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"ll_lat"
).
c_str
());
double
lllon
=
atof
(
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"ll_lon"
).
c_str
());
double
lllon
=
atof
(
metadataInterface
->
GetImageKeywordlist
().
GetMetadataByKey
(
"ll_lon"
).
c_str
());
SetParameterInt
(
"rgb.r"
,
metadataInterface
->
GetDefaultDisplay
()[
0
]);
SetParameterInt
(
"rgb.g"
,
metadataInterface
->
GetDefaultDisplay
()[
1
]);
SetParameterInt
(
"rgb.b"
,
metadataInterface
->
GetDefaultDisplay
()[
2
]);
SetParameterInt
(
"gcp.count"
,
metadataInterface
->
GetGCPCount
());
SetParameterString
(
"gcp.proj"
,
metadataInterface
->
GetGCPProjection
());
std
::
vector
<
std
::
string
>
gcp_ids
;
std
::
vector
<
std
::
string
>
gcp_imcoord
;
std
::
vector
<
std
::
string
>
gcp_geocoord
;
std
::
vector
<
std
::
string
>
gcp_infos
;
for
(
int
gcpIdx
=
0
;
gcpIdx
<
GetParameterInt
(
"gcp.count"
);
++
gcpIdx
)
{
gcp_ids
.
push_back
(
metadataInterface
->
GetGCPId
(
gcpIdx
));
gcp_infos
.
push_back
(
metadataInterface
->
GetGCPInfo
(
gcpIdx
));
std
::
ostringstream
oss
;
oss
<<
"["
<<
metadataInterface
->
GetGCPCol
(
gcpIdx
)
<<
", "
<<
metadataInterface
->
GetGCPRow
(
gcpIdx
)
<<
"]"
;
gcp_imcoord
.
push_back
(
oss
.
str
());
oss
.
str
(
""
);
oss
<<
"["
<<
metadataInterface
->
GetGCPX
(
gcpIdx
)
<<
", "
<<
metadataInterface
->
GetGCPY
(
gcpIdx
)
<<
", "
<<
metadataInterface
->
GetGCPZ
(
gcpIdx
)
<<
"]"
;
gcp_geocoord
.
push_back
(
oss
.
str
());
}
SetParameterStringList
(
"gcp.ids"
,
gcp_ids
);
SetParameterStringList
(
"gcp.imcoord"
,
gcp_imcoord
);
SetParameterStringList
(
"gcp.geocoord"
,
gcp_geocoord
);
SetParameterStringList
(
"gcp.info"
,
gcp_infos
);
// Retrieve footprint
SetParameterFloat
(
"ullat"
,
ullat
);
SetParameterFloat
(
"ullon"
,
ullon
);
SetParameterFloat
(
"urlat"
,
urlat
);
SetParameterFloat
(
"urlon"
,
urlon
);
SetParameterFloat
(
"lrlat"
,
lrlat
);
SetParameterFloat
(
"lrlon"
,
lrlon
);
SetParameterFloat
(
"lllat"
,
lllat
);
SetParameterFloat
(
"lllon"
,
lllon
);
double
centerlat
=
0.25
*
(
ullat
+
urlat
+
lrlat
+
lllat
);
double
centerlat
=
0.25
*
(
ullat
+
urlat
+
lrlat
+
lllat
);
double
centerlon
=
0.25
*
(
ullon
+
urlon
+
lrlon
+
lllon
);
double
centerlon
=
0.25
*
(
ullon
+
urlon
+
lrlon
+
lllon
);
...
@@ -278,31 +298,96 @@ private:
...
@@ -278,31 +298,96 @@ private:
coord2name
->
SetLon
(
centerlon
);
coord2name
->
SetLon
(
centerlon
);
coord2name
->
Evaluate
();
coord2name
->
Evaluate
();
if
(
!
coord2name
->
GetCountryName
().
empty
()
)
{
SetParameterString
(
"country"
,
coord2name
->
GetCountryName
());
ossOutput
<<
"
\t
Country : "
<<
GetParameterString
(
"country"
)
<<
std
::
endl
;
}
else
SetParameterString
(
"country"
,
"Not available"
);
if
(
!
coord2name
->
GetPlaceName
().
empty
()
)
if
(
!
coord2name
->
GetPlaceName
().
empty
()
)
{
SetParameterString
(
"town"
,
coord2name
->
GetPlaceName
());
SetParameterString
(
"town"
,
coord2name
->
GetPlaceName
());
ossOutput
<<
"
\t
Town : "
<<
GetParameterString
(
"town"
)
<<
std
::
endl
;
}
else
else
SetParameterString
(
"town"
,
"Not available"
);
SetParameterString
(
"town"
,
"Not available"
);
if
(
!
coord2name
->
GetCountryName
().
empty
()
)
// Retrieve footprint
SetParameterString
(
"country"
,
coord2name
->
GetCountryName
());
SetParameterFloat
(
"ullat"
,
ullat
);
else
SetParameterFloat
(
"ullon"
,
ullon
);
SetParameterString
(
"country"
,
"Not available"
);
SetParameterFloat
(
"urlat"
,
urlat
);
SetParameterFloat
(
"urlon"
,
urlon
);
SetParameterFloat
(
"lrlat"
,
lrlat
);
SetParameterFloat
(
"lrlon"
,
lrlon
);
SetParameterFloat
(
"lllat"
,
lllat
);
SetParameterFloat
(
"lllon"
,
lllon
);
ossOutput
<<
std
::
endl
<<
"Image footprint coordinates:"
<<
std
::
endl
;
ossOutput
<<
"
\t
Upper left corner (latitude,longitude) = ["
<<
GetParameterFloat
(
"ullat"
)
<<
","
<<
GetParameterFloat
(
"ullon"
)
<<
"]"
<<
std
::
endl
;
ossOutput
<<
"
\t
Upper right corner (latitude,longitude) = ["
<<
GetParameterFloat
(
"urlat"
)
<<
","
<<
GetParameterFloat
(
"urlon"
)
<<
"]"
<<
std
::
endl
;
ossOutput
<<
"
\t
Lower left corner (latitude,longitude) = ["
<<
GetParameterFloat
(
"lllat"
)
<<
","
<<
GetParameterFloat
(
"lllon"
)
<<
"]"
<<
std
::
endl
;
ossOutput
<<
"
\t
Lower right corner (latitude,longitude) = ["
<<
GetParameterFloat
(
"lrlat"
)
<<
","
<<
GetParameterFloat
(
"lrlon"
)
<<
"]"
<<
std
::
endl
;
}
}
catch
(
itk
::
ExceptionObject
&
err
)
catch
(
itk
::
ExceptionObject
&
err
)
{
{
//Do nothing at all
}
}
// Show result
otbAppLogINFO
(
<<
"Image informations:"
<<
std
::
endl
);
SetParameterInt
(
"rgb.r"
,
metadataInterface
->
GetDefaultDisplay
()[
0
]);
//otbAppLogINFO( << "General: ");
SetParameterInt
(
"rgb.g"
,
metadataInterface
->
GetDefaultDisplay
()[
1
]);
SetParameterInt
(
"rgb.b"
,
metadataInterface
->
GetDefaultDisplay
()[
2
]);
ossOutput
<<
std
::
endl
<<
"Image default RGB composition:"
<<
std
::
endl
;
ossOutput
<<
"
\t
[R,G,B] = ["
<<
GetParameterInt
(
"rgb.r"
)
<<
","
<<
GetParameterInt
(
"rgb.g"
)
<<
","
<<
GetParameterInt
(
"rgb.b"
)
<<
"]"
<<
std
::
endl
;
typedef
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>
ParametersListType
;
SetParameterInt
(
"gcp.count"
,
metadataInterface
->
GetGCPCount
());
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>
appList
=
GetOutputParametersSumUp
();
SetParameterString
(
"gcp.proj"
,
metadataInterface
->
GetGCPProjection
());
for
(
ParametersListType
::
const_iterator
it
=
appList
.
begin
();
it
!=
appList
.
end
();
++
it
)
ossOutput
<<
std
::
endl
<<
"Ground control points information:"
<<
std
::
endl
;
ossOutput
<<
"
\t
Number of GCPs = "
<<
GetParameterInt
(
"gcp.count"
)
<<
std
::
endl
;
ossOutput
<<
"
\t
GCPs projection = "
<<
GetParameterString
(
"gcp.proj"
)
<<
std
::
endl
;
std
::
vector
<
std
::
string
>
gcp_ids
;
std
::
vector
<
std
::
string
>
gcp_imcoord
;
std
::
vector
<
std
::
string
>
gcp_geocoord
;
std
::
vector
<
std
::
string
>
gcp_infos
;
for
(
int
gcpIdx
=
0
;
gcpIdx
<
GetParameterInt
(
"gcp.count"
);
++
gcpIdx
)
{
if
(
gcpIdx
==
0
)
ossOutput
<<
"
\t
GCP individual informations:"
<<
std
::
endl
;
gcp_ids
.
push_back
(
metadataInterface
->
GetGCPId
(
gcpIdx
));
gcp_infos
.
push_back
(
metadataInterface
->
GetGCPInfo
(
gcpIdx
));
std
::
ostringstream
oss
;
oss
<<
"["
<<
metadataInterface
->
GetGCPCol
(
gcpIdx
)
<<
", "
<<
metadataInterface
->
GetGCPRow
(
gcpIdx
)
<<
"]"
;
gcp_imcoord
.
push_back
(
oss
.
str
());
oss
.
str
(
""
);
oss
<<
"["
<<
metadataInterface
->
GetGCPX
(
gcpIdx
)
<<
", "
<<
metadataInterface
->
GetGCPY
(
gcpIdx
)
<<
", "
<<
metadataInterface
->
GetGCPZ
(
gcpIdx
)
<<
"]"
;
gcp_geocoord
.
push_back
(
oss
.
str
());
ossOutput
<<
"
\t\t
ID ="
<<
gcp_ids
.
back
()
<<
std
::
endl
;
ossOutput
<<
"
\t\t
Info ="
<<
gcp_infos
.
back
()
<<
std
::
endl
;
ossOutput
<<
"
\t\t
Image coordinates ="
<<
gcp_imcoord
.
back
()
<<
std
::
endl
;
ossOutput
<<
"
\t\t
Ground coordinates ="
<<
gcp_geocoord
.
back
()
<<
std
::
endl
;
}
SetParameterStringList
(
"gcp.ids"
,
gcp_ids
);
SetParameterStringList
(
"gcp.imcoord"
,
gcp_imcoord
);
SetParameterStringList
(
"gcp.geocoord"
,
gcp_geocoord
);
SetParameterStringList
(
"gcp.info"
,
gcp_infos
);
if
(
IsParameterEnabled
(
"keywordlist"
)
)
{
{
otbAppLogINFO
(
<<
it
->
first
<<
" "
<<
it
->
second
);
std
::
ostringstream
osskeywordlist
;
osskeywordlist
<<
metadataInterface
->
GetImageKeywordlist
()
<<
std
::
endl
;
SetParameterString
(
"keyword"
,
osskeywordlist
.
str
());
ossOutput
<<
std
::
endl
<<
"Image OSSIM keywordlist (optional):"
<<
std
::
endl
;
ossOutput
<<
"
\t
"
<<
GetParameterString
(
"keyword"
)
<<
std
::
endl
;
}
}
//Display image informations in the dedicated logger
otbAppLogINFO
(
<<
ossOutput
.
str
()
);
}
}
};
};
...
...
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