python
import cv2 as cv
def function():
img = cv.imread("../images/test.jpg")
cv.imshow("test", img)
dsc = cv.applyColorMap(img, cv.COLORMAP_COOL)
cv.imshow("COOL", dsc)
img1 = cv.imread("../images/canjian.jpg")
color_image = cv.applyColorMap(img1, cv.COLORMAP_JET)
cv.imshow("JET", color_image)
cv.imshow("canjian", img1)
function()
cv.waitKey(0)
cv.destroyAllWindows()
python中的新知识点
- cv.applyColorMap()
- cv.COLORMAP_COOL
- cv.COLORMAP_JET
c++
#include "all.h"
using namespace std;
using namespace cv;
void customColorMap(Mat &image);
void MyClass::day006() {
Mat img = read(PATH + "\\images\\cat.jpg");
Mat dst = Mat::zeros(img.size(), img.type());
Mat gray;
imshow("input", img);
applyColorMap(img, dst, COLORMAP_SUMMER);
imshow("COLORMAP_SUMMER", dst);
cvtColor(img, gray, COLOR_BGR2GRAY);
imshow("gray", gray);
customColorMap(gray);
waitKey(0);
}
void customColorMap(Mat &image) {
int lu[256];
for (int i = 0; i < 256; i++) {
if (i > 127)
lu[i] = 255;
else
lu[i] = 0;
}
int row = image.rows;
int col = image.cols;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
int value = image.at<uchar>(i, j);
image.at<uchar>(i, j) = lu[value];
}
}
imshow("custom_map", image);
}
c++中的新知识点
- applyColorMap()
- COLORMAP_SUMMER
- COLOR_BGR2GRAY