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
9734ee13
Commit
9734ee13
authored
May 24, 2017
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7865 from LaurentBerger:UserColormap
parents
057c10ba
91e06e7c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
183 additions
and
1 deletion
+183
-1
imgproc.hpp
modules/imgproc/include/opencv2/imgproc.hpp
+9
-1
colormap.cpp
modules/imgproc/src/colormap.cpp
+28
-0
falsecolor.cpp
samples/cpp/falsecolor.cpp
+146
-0
No files found.
modules/imgproc/include/opencv2/imgproc.hpp
View file @
9734ee13
...
...
@@ -4133,9 +4133,17 @@ enum ColormapTypes
@param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3.
@param dst The result is the colormapped source image. Note: Mat::create is called on dst.
@param colormap The colormap to apply, see cv::ColormapTypes
*/
*/
CV_EXPORTS_W
void
applyColorMap
(
InputArray
src
,
OutputArray
dst
,
int
colormap
);
/** @brief Applies a user colormap on a given image.
@param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3.
@param dst The result is the colormapped source image. Note: Mat::create is called on dst.
@param userColor The colormap to apply of type CV_8UC1 or CV_8UC3 and size 256
*/
CV_EXPORTS_W
void
applyColorMap
(
InputArray
src
,
OutputArray
dst
,
InputArray
userColor
);
//! @} imgproc_colormap
//! @addtogroup imgproc_draw
...
...
modules/imgproc/src/colormap.cpp
View file @
9734ee13
...
...
@@ -490,6 +490,22 @@ namespace colormap
}
};
// UserColormap .
class
UserColorMap
:
public
ColorMap
{
public
:
UserColorMap
(
Mat
c
)
:
ColorMap
()
{
init
(
c
);
}
void
init
(
Mat
c
)
{
this
->
_lut
=
c
;
}
void
init
(
int
n
)
{
CV_Error
(
Error
::
StsAssert
,
format
(
"unused method in UserColormap init(%d)."
,
n
));
}
};
void
ColorMap
::
operator
()(
InputArray
_src
,
OutputArray
_dst
)
const
{
CV_INSTRUMENT_REGION
()
...
...
@@ -546,4 +562,16 @@ namespace colormap
delete
cm
;
}
void
applyColorMap
(
InputArray
src
,
OutputArray
dst
,
InputArray
userColor
)
{
if
(
userColor
.
size
()
!=
Size
(
1
,
256
))
CV_Error
(
Error
::
StsAssert
,
"cv::LUT only supports tables of size 256."
);
if
(
userColor
.
type
()
!=
CV_8UC1
&&
userColor
.
type
()
!=
CV_8UC3
)
CV_Error
(
Error
::
StsAssert
,
"cv::LUT only supports tables CV_8UC1 or CV_8UC3."
);
colormap
::
UserColorMap
cm
(
userColor
.
getMat
());
(
cm
)(
src
,
dst
);
}
}
samples/cpp/falsecolor.cpp
0 → 100644
View file @
9734ee13
#include <opencv2/opencv.hpp>
using
namespace
cv
;
using
namespace
std
;
enum
MyShape
{
MyCIRCLE
=
0
,
MyRECTANGLE
,
MyELLIPSE
};
struct
ParamColorMar
{
int
iColormap
;
Mat
img
;
};
Ptr
<
Mat
>
lutRND
;
String
winName
=
"False color"
;
static
void
TrackColorMap
(
int
x
,
void
*
r
)
{
ParamColorMar
*
p
=
(
ParamColorMar
*
)
r
;
Mat
dst
;
p
->
iColormap
=
x
;
if
(
x
==
cv
::
COLORMAP_PARULA
+
1
)
{
if
(
!
lutRND
)
{
RNG
ra
;
Mat
*
palette
=
new
Mat
(
256
,
1
,
CV_8UC3
);
ra
.
fill
(
*
palette
,
RNG
::
UNIFORM
,
0
,
256
);
lutRND
=
Ptr
<
Mat
>
(
palette
);
}
applyColorMap
(
p
->
img
,
dst
,
*
lutRND
.
get
());
}
else
applyColorMap
(
p
->
img
,
dst
,
p
->
iColormap
);
String
colorMapName
;
switch
(
p
->
iColormap
)
{
case
COLORMAP_AUTUMN
:
colorMapName
=
"Colormap : Autumn"
;
break
;
case
COLORMAP_BONE
:
colorMapName
=
"Colormap : Bone"
;
break
;
case
COLORMAP_JET
:
colorMapName
=
"Colormap : Jet"
;
break
;
case
COLORMAP_WINTER
:
colorMapName
=
"Colormap : Winter"
;
break
;
case
COLORMAP_RAINBOW
:
colorMapName
=
"Colormap : Rainbow"
;
break
;
case
COLORMAP_OCEAN
:
colorMapName
=
"Colormap : Ocean"
;
break
;
case
COLORMAP_SUMMER
:
colorMapName
=
"Colormap : Summer"
;
break
;
case
COLORMAP_SPRING
:
colorMapName
=
"Colormap : Spring"
;
break
;
case
COLORMAP_COOL
:
colorMapName
=
"Colormap : Cool"
;
break
;
case
COLORMAP_HSV
:
colorMapName
=
"Colormap : HSV"
;
break
;
case
COLORMAP_PINK
:
colorMapName
=
"Colormap : Pink"
;
break
;
case
COLORMAP_HOT
:
colorMapName
=
"Colormap : Hot"
;
break
;
case
COLORMAP_PARULA
:
colorMapName
=
"Colormap : Parula"
;
break
;
default:
colorMapName
=
"User colormap : random"
;
break
;
}
putText
(
dst
,
colorMapName
,
Point
(
10
,
20
),
cv
::
FONT_HERSHEY_SIMPLEX
,
1
,
Scalar
(
255
,
255
,
255
));
imshow
(
winName
,
dst
);
}
static
Mat
DrawMyImage
(
int
thickness
,
int
nbShape
)
{
Mat
img
=
Mat
::
zeros
(
500
,
256
*
thickness
+
100
,
CV_8UC1
);
int
offsetx
=
50
,
offsety
=
25
;
int
lineLenght
=
50
;
for
(
int
i
=
0
;
i
<
256
;
i
++
)
line
(
img
,
Point
(
thickness
*
i
+
offsetx
,
offsety
),
Point
(
thickness
*
i
+
offsetx
,
offsety
+
lineLenght
),
Scalar
(
i
),
thickness
);
RNG
r
;
Point
center
;
int
radius
;
int
width
,
height
;
int
angle
;
Rect
rc
;
for
(
int
i
=
1
;
i
<=
nbShape
;
i
++
)
{
int
typeShape
=
r
.
uniform
(
MyCIRCLE
,
MyELLIPSE
+
1
);
switch
(
typeShape
)
{
case
MyCIRCLE
:
center
=
Point
(
r
.
uniform
(
offsetx
,
img
.
cols
-
offsetx
),
r
.
uniform
(
offsety
+
lineLenght
,
img
.
rows
-
offsety
));
radius
=
r
.
uniform
(
1
,
min
(
offsetx
,
offsety
));
circle
(
img
,
center
,
radius
,
Scalar
(
i
),
-
1
);
break
;
case
MyRECTANGLE
:
center
=
Point
(
r
.
uniform
(
offsetx
,
img
.
cols
-
offsetx
),
r
.
uniform
(
offsety
+
lineLenght
,
img
.
rows
-
offsety
));
width
=
r
.
uniform
(
1
,
min
(
offsetx
,
offsety
));
height
=
r
.
uniform
(
1
,
min
(
offsetx
,
offsety
));
rc
=
Rect
(
center
-
Point
(
width
,
height
)
/
2
,
center
+
Point
(
width
,
height
)
/
2
);
rectangle
(
img
,
rc
,
Scalar
(
i
),
-
1
);
break
;
case
MyELLIPSE
:
center
=
Point
(
r
.
uniform
(
offsetx
,
img
.
cols
-
offsetx
),
r
.
uniform
(
offsety
+
lineLenght
,
img
.
rows
-
offsety
));
width
=
r
.
uniform
(
1
,
min
(
offsetx
,
offsety
));
height
=
r
.
uniform
(
1
,
min
(
offsetx
,
offsety
));
angle
=
r
.
uniform
(
0
,
180
);
ellipse
(
img
,
center
,
Size
(
width
/
2
,
height
/
2
),
angle
,
0
,
360
,
Scalar
(
i
),
-
1
);
break
;
}
}
return
img
;
}
int
main
(
void
)
{
ParamColorMar
p
;
Mat
img
=
DrawMyImage
(
2
,
256
);
p
.
img
=
img
;
p
.
iColormap
=
0
;
imshow
(
"Gray image"
,
img
);
namedWindow
(
winName
);
createTrackbar
(
"colormap"
,
winName
,
&
p
.
iColormap
,
1
,
TrackColorMap
,(
void
*
)
&
p
);
setTrackbarMin
(
"colormap"
,
winName
,
cv
::
COLORMAP_AUTUMN
);
setTrackbarMax
(
"colormap"
,
winName
,
cv
::
COLORMAP_PARULA
+
1
);
setTrackbarPos
(
"colormap"
,
winName
,
-
1
);
TrackColorMap
(
0
,(
void
*
)
&
p
);
waitKey
(
0
);
return
0
;
}
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