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
a1b3ba02
Commit
a1b3ba02
authored
Jul 01, 2013
by
siddharth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add color_boost + doc
parent
88aa4a99
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
9 deletions
+72
-9
decolor.rst
modules/photo/doc/decolor.rst
+20
-0
photo.hpp
modules/photo/include/opencv2/photo.hpp
+1
-1
contrast_preserve.cpp
modules/photo/src/contrast_preserve.cpp
+39
-1
test_decolor.cpp
modules/photo/test/test_decolor.cpp
+12
-7
No files found.
modules/photo/doc/decolor.rst
0 → 100644
View file @
a1b3ba02
Decolorization
==============
.. highlight:: cpp
decolor
-------
Transforms a color image to a grayscale image. It is a basic tool in digital printing, stylized black-and-white photograph rendering, and in many single channel image processing applications.
.. ocv:function:: void decolor( InputArray src, OutputArray grayscale, OutputArray color_boost )
:param src: Input 8-bit 3-channel image.
:param grayscale: Output 8-bit 1-channel image.
:param color_boost: Output 8-bit 3-channel image.
This function is to be applied on color images.
modules/photo/include/opencv2/photo.hpp
View file @
a1b3ba02
...
@@ -288,7 +288,7 @@ public:
...
@@ -288,7 +288,7 @@ public:
CV_EXPORTS_W
Ptr
<
MergeRobertson
>
createMergeRobertson
();
CV_EXPORTS_W
Ptr
<
MergeRobertson
>
createMergeRobertson
();
CV_EXPORTS_W
void
decolor
(
InputArray
src
,
OutputArray
grayscale
);
CV_EXPORTS_W
void
decolor
(
InputArray
src
,
OutputArray
grayscale
,
OutputArray
color_boost
);
}
// cv
}
// cv
...
...
modules/photo/src/contrast_preserve.cpp
View file @
a1b3ba02
...
@@ -17,12 +17,15 @@ int rounding(double a)
...
@@ -17,12 +17,15 @@ int rounding(double a)
return
int
(
a
+
0.5
);
return
int
(
a
+
0.5
);
}
}
void
cv
::
decolor
(
InputArray
_src
,
OutputArray
_dst
)
void
cv
::
decolor
(
InputArray
_src
,
OutputArray
_dst
,
OutputArray
_boost
)
{
{
Mat
I
=
_src
.
getMat
();
Mat
I
=
_src
.
getMat
();
_dst
.
create
(
I
.
size
(),
CV_8UC1
);
_dst
.
create
(
I
.
size
(),
CV_8UC1
);
Mat
dst
=
_dst
.
getMat
();
Mat
dst
=
_dst
.
getMat
();
_boost
.
create
(
I
.
size
(),
CV_8UC3
);
Mat
color_boost
=
_boost
.
getMat
();
if
(
!
I
.
data
)
if
(
!
I
.
data
)
{
{
cout
<<
"Could not open or find the image"
<<
endl
;
cout
<<
"Could not open or find the image"
<<
endl
;
...
@@ -162,5 +165,40 @@ void cv::decolor(InputArray _src, OutputArray _dst)
...
@@ -162,5 +165,40 @@ void cv::decolor(InputArray _src, OutputArray _dst)
Gray
.
convertTo
(
dst
,
CV_8UC1
,
255
);
Gray
.
convertTo
(
dst
,
CV_8UC1
,
255
);
/////////////////////////////////// Contrast Boosting /////////////////////////////////
Mat
lab
=
Mat
(
img
.
size
(),
CV_8UC3
);
Mat
color
=
Mat
(
img
.
size
(),
CV_8UC3
);
Mat
l
=
Mat
(
img
.
size
(),
CV_8UC1
);
Mat
a
=
Mat
(
img
.
size
(),
CV_8UC1
);
Mat
b
=
Mat
(
img
.
size
(),
CV_8UC1
);
cvtColor
(
I
,
lab
,
COLOR_BGR2Lab
);
int
h1
=
img
.
size
().
height
;
int
w1
=
img
.
size
().
width
;
for
(
int
i
=
0
;
i
<
h1
;
i
++
)
for
(
int
j
=
0
;
j
<
w1
;
j
++
)
{
l
.
at
<
uchar
>
(
i
,
j
)
=
lab
.
at
<
uchar
>
(
i
,
j
*
3
+
0
);
a
.
at
<
uchar
>
(
i
,
j
)
=
lab
.
at
<
uchar
>
(
i
,
j
*
3
+
1
);
b
.
at
<
uchar
>
(
i
,
j
)
=
lab
.
at
<
uchar
>
(
i
,
j
*
3
+
2
);
}
for
(
int
i
=
0
;
i
<
h1
;
i
++
)
for
(
int
j
=
0
;
j
<
w1
;
j
++
)
{
l
.
at
<
uchar
>
(
i
,
j
)
=
255.0
*
Gray
.
at
<
float
>
(
i
,
j
);
}
for
(
int
i
=
0
;
i
<
h1
;
i
++
)
for
(
int
j
=
0
;
j
<
w1
;
j
++
)
{
lab
.
at
<
uchar
>
(
i
,
j
*
3
+
0
)
=
l
.
at
<
uchar
>
(
i
,
j
);
lab
.
at
<
uchar
>
(
i
,
j
*
3
+
1
)
=
a
.
at
<
uchar
>
(
i
,
j
);
lab
.
at
<
uchar
>
(
i
,
j
*
3
+
2
)
=
b
.
at
<
uchar
>
(
i
,
j
);
}
cvtColor
(
lab
,
color_boost
,
COLOR_Lab2BGR
);
}
}
modules/photo/test/test_decolor.cpp
View file @
a1b3ba02
...
@@ -16,19 +16,24 @@ TEST(Photo_Decolor, regression)
...
@@ -16,19 +16,24 @@ TEST(Photo_Decolor, regression)
{
{
string
folder
=
string
(
cvtest
::
TS
::
ptr
()
->
get_data_path
())
+
"decolor/"
;
string
folder
=
string
(
cvtest
::
TS
::
ptr
()
->
get_data_path
())
+
"decolor/"
;
string
original_path
=
folder
+
"color_image_1.png"
;
string
original_path
=
folder
+
"color_image_1.png"
;
string
expected_path
=
folder
+
"grayscale_image_1.png"
;
string
expected_path1
=
folder
+
"grayscale_image_1.png"
;
string
expected_path2
=
folder
+
"color_boost_image_1.png"
;
Mat
original
=
imread
(
original_path
,
IMREAD_COLOR
);
Mat
original
=
imread
(
original_path
,
IMREAD_COLOR
);
Mat
expected
=
imread
(
expected_path
,
IMREAD_GRAYSCALE
);
Mat
expected1
=
imread
(
expected_path1
,
IMREAD_GRAYSCALE
);
Mat
expected2
=
imread
(
expected_path2
,
IMREAD_COLOR
);
ASSERT_FALSE
(
original
.
empty
())
<<
"Could not load input image "
<<
original_path
;
ASSERT_FALSE
(
original
.
empty
())
<<
"Could not load input image "
<<
original_path
;
ASSERT_FALSE
(
expected
.
empty
())
<<
"Could not load reference image "
<<
expected_path
;
ASSERT_FALSE
(
expected1
.
empty
())
<<
"Could not load reference image "
<<
expected_path1
;
ASSERT_FALSE
(
expected2
.
empty
())
<<
"Could not load reference image "
<<
expected_path2
;
Mat
resul
t
;
Mat
grayscale
,
color_boos
t
;
decolor
(
original
,
resul
t
);
decolor
(
original
,
grayscale
,
color_boos
t
);
DUMP
(
result
,
expected_path
+
".res.png"
);
DUMP
(
grayscale
,
expected_path1
+
".grayscale.png"
);
DUMP
(
color_boost
,
expected_path2
+
".color_boost.png"
);
ASSERT_EQ
(
0
,
norm
(
result
!=
expected
));
ASSERT_EQ
(
0
,
norm
(
grayscale
!=
expected1
));
ASSERT_EQ
(
0
,
norm
(
color_boost
!=
expected2
));
}
}
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