ApplyColorMap can be used with a user colormap

pull/7865/head
LaurentBerger 8 years ago
parent 36b5abf6b7
commit 61b9484155
  1. 10
      modules/imgproc/include/opencv2/imgproc.hpp
  2. 33
      modules/imgproc/src/colormap.cpp

@ -4097,9 +4097,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

@ -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;
}
}

Loading…
Cancel
Save