1. python实现
import cv2
import numpy as np
from skimage import data, exposure, img_as_float
import matplotlib.pyplot as plt
imgOrigin = cv2.imread("C:\\1.tif", cv2.CV_8UC1)
clahe = cv2.createCLAHE(clipLimit=20, tileGridSize=(8, 8))
imgCLAHE = clahe.apply(imgOrigin)
imgCLAHE_RGB = np.zeros((3,) + imgCLAHE.shape, dtype=imgCLAHE.dtype)
imgCLAHE_RGB[1] = imgCLAHE
imgCLAHE_RGB = np.transpose(imgCLAHE_RGB, [1, 2, 0])
cv2.imshow('createCLAHE', imgCLAHE_RGB) # BGR
cv2.waitKey(1000)
用自带的函数applyColorMap,实现默认的伪彩
for i in range(22):
dst = cv2.applyColorMap(imgCLAHE,i)
2. EmguCV
mat的命名空间是 EmguCV
public Mat ByteArrayToImage8(byte[] sourceArray, int width, int height, int R)
{
Mat mat = new Mat(height, width, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
mat.SetTo<byte>(sourceArray);
Image<Rgb, byte> Sub = mat.ToImage<Rgb, byte>();
Image<Rgb, byte> array = new Image<Rgb, byte>(width, height, new Rgb(0, 0, 0));
array.SetZero();
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
array.Data[i, j, R] = Sub.Data[i, j, R];
}
}
return array.Mat;
}
3. OpenCvSharp
mat的命名空间是 OpenCvSharp
public Mat MatToChannels(Mat src)
{
Mat dst = new Mat(src.Size(), MatType.CV_8UC3);
int height = src.Rows;
int width = src.Cols;
int cn = dst.Channels();
for (int row = 0; row < height; row++)
{
for (int col = 0; col < width; col++)
{
int value = src.At<Vec3b>(row, col)[0];
Vec3b color = new Vec3b
{
Item0 = 0,
Item1 = 0,
Item2 = value
};
//赋值
dst.Set<Vec3b>(row, col, color);
}
}
return dst;
}