Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
a5e11079
Commit
a5e11079
authored
Jul 04, 2013
by
Fedor Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes, missing files, tests
parent
122f85f3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
41 deletions
+81
-41
grfmt_hdr.cpp
modules/highgui/src/grfmt_hdr.cpp
+3
-5
grfmt_tiff.cpp
modules/highgui/src/grfmt_tiff.cpp
+11
-25
grfmt_tiff.hpp
modules/highgui/src/grfmt_tiff.hpp
+1
-1
photo.hpp
modules/photo/include/opencv2/photo.hpp
+17
-1
hdr_fusion.cpp
modules/photo/src/hdr_fusion.cpp
+12
-7
test_hdr.cpp
modules/photo/test/test_hdr.cpp
+37
-2
No files found.
modules/highgui/src/grfmt_hdr.cpp
View file @
a5e11079
...
...
@@ -92,11 +92,9 @@ bool HdrDecoder::readData(Mat& img)
bool
HdrDecoder
::
checkSignature
(
const
String
&
signature
)
const
{
if
(
signature
.
size
()
>=
(
m_signature
.
size
())
&&
!
memcmp
(
signature
.
c_str
(),
m_signature
.
c_str
(),
m_signature
.
size
()))
return
true
;
if
(
signature
.
size
()
>=
(
m_signature
.
size
())
&&
!
memcmp
(
signature
.
c_str
(),
m_signature_alt
.
c_str
(),
m_signature_alt
.
size
()))
if
(
signature
.
size
()
>=
m_signature
.
size
()
&&
(
!
memcmp
(
signature
.
c_str
(),
m_signature
.
c_str
(),
m_signature
.
size
())
||
!
memcmp
(
signature
.
c_str
(),
m_signature_alt
.
c_str
(),
m_signature_alt
.
size
())))
return
true
;
return
false
;
}
...
...
modules/highgui/src/grfmt_tiff.cpp
View file @
a5e11079
...
...
@@ -47,6 +47,7 @@
#include "precomp.hpp"
#include "grfmt_tiff.hpp"
#include <opencv2/imgproc.hpp>
namespace
cv
{
...
...
@@ -413,22 +414,13 @@ bool TiffDecoder::readHdrData(Mat& img)
size
-=
strip_size
*
sizeof
(
float
);
}
close
();
ptr
=
img
.
ptr
<
float
>
();
for
(
size_t
i
=
0
;
i
<
img
.
total
();
i
++
,
ptr
+=
3
)
if
(
photometric
==
PHOTOMETRIC_LOGLUV
)
{
if
(
photometric
==
PHOTOMETRIC_LOGLUV
)
{
float
r
=
3.240479
f
*
ptr
[
0
]
+
-
1.537150
f
*
ptr
[
1
]
+
-
0.498535
f
*
ptr
[
2
];
float
g
=
-
0.969256
f
*
ptr
[
0
]
+
1.875991
f
*
ptr
[
1
]
+
0.041556
f
*
ptr
[
2
];
float
b
=
0.055648
f
*
ptr
[
0
]
+
-
0.204043
f
*
ptr
[
1
]
+
1.057311
f
*
ptr
[
2
];
ptr
[
0
]
=
b
;
ptr
[
1
]
=
g
;
ptr
[
2
]
=
r
;
}
else
{
float
tmp
=
ptr
[
0
];
ptr
[
0
]
=
ptr
[
2
];
ptr
[
2
]
=
tmp
;
}
cvtColor
(
img
,
img
,
COLOR_XYZ2BGR
);
}
else
{
cvtColor
(
img
,
img
,
COLOR_RGB2BGR
);
}
return
true
;
}
...
...
@@ -614,16 +606,10 @@ bool TiffEncoder::writeLibTiff( const Mat& img, const std::vector<int>& params)
return
true
;
}
bool
TiffEncoder
::
writeHdr
(
const
Mat
&
img
)
bool
TiffEncoder
::
writeHdr
(
const
Mat
&
_
img
)
{
float
*
ptr
=
const_cast
<
float
*>
(
img
.
ptr
<
float
>
());
for
(
size_t
i
=
0
;
i
<
img
.
total
();
i
++
,
ptr
+=
3
)
{
float
x
=
0.412453
f
*
ptr
[
2
]
+
0.357580
f
*
ptr
[
1
]
+
0.180423
f
*
ptr
[
0
];
float
y
=
0.212671
f
*
ptr
[
2
]
+
0.715160
f
*
ptr
[
1
]
+
0.072169
f
*
ptr
[
0
];
float
z
=
0.019334
f
*
ptr
[
2
]
+
0.119193
f
*
ptr
[
1
]
+
0.950227
f
*
ptr
[
0
];
ptr
[
0
]
=
x
;
ptr
[
1
]
=
y
;
ptr
[
2
]
=
z
;
}
Mat
img
;
cvtColor
(
_img
,
img
,
COLOR_BGR2XYZ
);
TIFF
*
tif
=
TIFFOpen
(
m_filename
.
c_str
(),
"w"
);
if
(
!
tif
)
{
...
...
@@ -638,7 +624,7 @@ bool TiffEncoder::writeHdr(const Mat& img)
TIFFSetField
(
tif
,
TIFFTAG_SGILOGDATAFMT
,
SGILOGDATAFMT_FLOAT
);
TIFFSetField
(
tif
,
TIFFTAG_ROWSPERSTRIP
,
1
);
int
strip_size
=
3
*
img
.
cols
;
ptr
=
const_cast
<
float
*>
(
img
.
ptr
<
float
>
());
float
*
ptr
=
const_cast
<
float
*>
(
img
.
ptr
<
float
>
());
for
(
int
i
=
0
;
i
<
img
.
rows
;
i
++
,
ptr
+=
strip_size
)
{
TIFFWriteEncodedStrip
(
tif
,
i
,
ptr
,
strip_size
*
sizeof
(
float
));
...
...
modules/highgui/src/grfmt_tiff.hpp
View file @
a5e11079
...
...
@@ -53,7 +53,7 @@ enum TiffCompression
{
TIFF_UNCOMP
=
1
,
TIFF_HUFFMAN
=
2
,
TIFF_PACKBITS
=
32773
,
TIFF_PACKBITS
=
32773
};
enum
TiffByteOrder
...
...
modules/photo/include/opencv2/photo.hpp
View file @
a5e11079
...
...
@@ -59,6 +59,20 @@ enum
INPAINT_TELEA
=
1
// A. Telea algorithm
};
//! the tonemapping algorithm
enum
tonemap_algorithms
{
TONEMAP_LINEAR
,
TONEMAP_DRAGO
,
// Adaptive Logarithmic Mapping For
// Displaying High Contrast Scenes
TONEMAP_REINHARD
,
// Dynamic Range Reduction Inspired
// by Photoreceptor Physiology
TONEMAP_DURAND
,
// Fast Bilateral Filtering for the
// Display of High-Dynamic-Range Images
TONEMAP_COUNT
};
//! restores the damaged image areas using one of the available intpainting algorithms
CV_EXPORTS_W
void
inpaint
(
InputArray
src
,
InputArray
inpaintMask
,
OutputArray
dst
,
double
inpaintRadius
,
int
flags
);
...
...
@@ -80,7 +94,9 @@ CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs,
float
h
=
3
,
float
hColor
=
3
,
int
templateWindowSize
=
7
,
int
searchWindowSize
=
21
);
CV_EXPORTS_W
void
makeHDR
(
InputArrayOfArrays
srcImgs
,
std
::
vector
<
float
>
expTimes
,
OutputArray
dst
);
CV_EXPORTS_W
void
makeHDR
(
InputArrayOfArrays
srcImgs
,
const
std
::
vector
<
float
>&
exp_times
,
OutputArray
dst
);
CV_EXPORTS_W
void
tonemap
(
InputArray
src
,
OutputArray
dst
,
tonemap_algorithms
algorithm
,
std
::
vector
<
float
>&
params
=
std
::
vector
<
float
>
());
}
// cv
...
...
modules/photo/src/hdr_fusion.cpp
View file @
a5e11079
...
...
@@ -64,29 +64,34 @@ static void generateResponce(float responce[])
responce
[
0
]
=
responce
[
1
];
}
void
makeHDR
(
InputArrayOfArrays
_images
,
std
::
vector
<
float
>
exp_times
,
OutputArray
_dst
)
void
makeHDR
(
InputArrayOfArrays
_images
,
const
std
::
vector
<
float
>&
_
exp_times
,
OutputArray
_dst
)
{
std
::
vector
<
Mat
>
images
;
_images
.
getMatVector
(
images
);
if
(
images
.
empty
())
{
printf
(
"Need at least one vector image.
"
);
CV_Error
(
Error
::
StsBadArg
,
"Need at least one image
"
);
}
if
(
images
.
size
()
!=
exp_times
.
size
())
{
printf
(
"Number of images and number of exposure times must be equal."
);
if
(
images
.
size
()
!=
_
exp_times
.
size
())
{
CV_Error
(
Error
::
StsBadArg
,
"Number of images and number of exposure times must be equal."
);
}
int
width
=
images
[
0
].
cols
;
int
height
=
images
[
0
].
rows
;
for
(
size_t
i
=
0
;
i
<
images
.
size
();
i
++
)
{
if
(
images
[
i
].
cols
!=
width
||
images
[
i
].
rows
!=
height
)
{
printf
(
"Image dimensions must be equal."
);
CV_Error
(
Error
::
StsBadArg
,
"Image dimensions must be equal."
);
}
if
(
images
[
i
].
type
()
!=
CV_8UC3
)
{
printf
(
"Images must have CV_8UC3 type."
);
CV_Error
(
Error
::
StsBadArg
,
"Images must have CV_8UC3 type."
);
}
}
_dst
.
create
(
images
[
0
].
size
(),
CV_32FC3
);
Mat
result
=
_dst
.
getMat
();
std
::
vector
<
float
>
exp_times
(
_exp_times
.
size
());
for
(
size_t
i
=
0
;
i
<
exp_times
.
size
();
i
++
)
{
exp_times
[
i
]
=
log
(
_exp_times
[
i
]);
}
float
weights
[
256
],
responce
[
256
];
triangleWeights
(
weights
);
generateResponce
(
responce
);
...
...
@@ -104,7 +109,7 @@ void makeHDR(InputArrayOfArrays _images, std::vector<float> exp_times, OutputArr
weights
[
img_ptr
[
2
]])
/
3
;
weight_sum
+=
w
;
for
(
int
channel
=
0
;
channel
<
3
;
channel
++
)
{
sum
[
channel
]
+=
w
*
(
responce
[
img_ptr
[
channel
]]
-
log
(
exp_times
[
im
])
);
sum
[
channel
]
+=
w
*
(
responce
[
img_ptr
[
channel
]]
-
exp_times
[
im
]
);
}
}
for
(
int
channel
=
0
;
channel
<
3
;
channel
++
)
{
...
...
modules/photo/test/test_hdr.cpp
View file @
a5e11079
...
...
@@ -72,7 +72,41 @@ TEST(Photo_MakeHdr, regression)
Mat
result
;
makeHDR
(
images
,
times
,
result
);
double
m
in
=
0.0
,
m
ax
=
1.0
;
minMaxLoc
(
abs
(
result
-
expected
),
&
min
,
&
max
);
double
max
=
1.0
;
minMaxLoc
(
abs
(
result
-
expected
),
NULL
,
&
max
);
ASSERT_TRUE
(
max
<
0.01
);
}
TEST
(
Photo_Tonemap
,
regression
)
{
string
folder
=
string
(
cvtest
::
TS
::
ptr
()
->
get_data_path
())
+
"hdr/"
;
vector
<
string
>
file_names
(
TONEMAP_COUNT
);
file_names
[
TONEMAP_DRAGO
]
=
folder
+
"grand_canal_drago_2.2.png"
;
file_names
[
TONEMAP_REINHARD
]
=
folder
+
"grand_canal_reinhard_2.2.png"
;
file_names
[
TONEMAP_DURAND
]
=
folder
+
"grand_canal_durand_2.2.png"
;
file_names
[
TONEMAP_LINEAR
]
=
folder
+
"grand_canal_linear_map_2.2.png"
;
vector
<
Mat
>
images
(
TONEMAP_COUNT
);
for
(
int
i
=
0
;
i
<
TONEMAP_COUNT
;
i
++
)
{
images
[
i
]
=
imread
(
file_names
[
i
]);
ASSERT_FALSE
(
images
[
i
].
empty
())
<<
"Could not load input image "
<<
file_names
[
i
];
}
string
hdr_file_name
=
folder
+
"grand_canal_rle.hdr"
;
Mat
img
=
imread
(
hdr_file_name
,
-
1
);
ASSERT_FALSE
(
img
.
empty
())
<<
"Could not load input image "
<<
hdr_file_name
;
vector
<
float
>
param
(
1
);
param
[
0
]
=
2.2
f
;
for
(
int
i
=
TONEMAP_DURAND
;
i
<
TONEMAP_COUNT
;
i
++
)
{
Mat
result
;
tonemap
(
img
,
result
,
static_cast
<
tonemap_algorithms
>
(
i
),
param
);
result
.
convertTo
(
result
,
CV_8UC3
,
255
);
double
max
=
1.0
;
minMaxLoc
(
abs
(
result
-
images
[
i
]),
NULL
,
&
max
);
ASSERT_FALSE
(
max
>
0
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment