1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

ApplyColorMap can be used with a user colormap

This commit is contained in:
LaurentBerger
2016-12-15 10:17:05 +01:00
parent 36b5abf6b7
commit 61b9484155
2 changed files with 42 additions and 1 deletions
+33
View File
@@ -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, "unused method in UserColormap.");
}
};
void ColorMap::operator()(InputArray _src, OutputArray _dst) const
{
CV_INSTRUMENT_REGION()
@@ -546,4 +562,21 @@ namespace colormap
delete cm;
}
void applyColorMap(InputArray src, OutputArray dst, InputArray userColor)
{
if (userColor.total() != 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::ColorMap* cm = (colormap::ColorMap*) (new colormap::UserColorMap(userColor.getMat()));
if (!cm)
CV_Error(Error::StsBadArg, "Unknown colormap id; use one of COLORMAP_*");
(*cm)(src, dst);
delete cm;
}
}