Haematoxylin-Eosin-DAB简称HED,实现原理是参考python中的rgb2hed方法
/* rgb转hed
R G B
M=[0.65, 0.7 , 0.29] Hematoxylin
[0.07, 0.99, 0.11] Eosin
[0.27, 0.57, 0.78] DAB
*/
cv::Mat rgb2hed(const cv::Mat& image)
{
cv::Mat img = image.clone();
float hed_value[3][3] = { 0.65, 0.70, 0.29, 0.07, 0.99 ,0.11, 0.27, 0.57 ,0.78 };
cv::Mat hed_matrix = cv::Mat(3, 3, CV_32FC1, hed_value);
cv::Mat hed_matrix_inv = hed_matrix.inv();
//归一化
cv::Mat logmat;
img.convertTo(img, CV_32FC3, 1.0 / 255);
cv::max(img, 1E-6, img);
cv::log(img, logmat);
float log_adjust = log(1E-6);
cv::Mat logmat_adjust = logmat / log_adjust;
cv::Mat sample = logmat_adjust.reshape(1, img.rows * img.cols);
cv::Mat stains = sample * hed_matrix_inv;
cv::Mat hed = stains.reshape(3, img.rows);
cv::max(hed , 0, hed );
return hed ;
}
int main()
{
cv::Mat mt = imread("xx.jpg");
cvtColor(mt,mt,CV_BGR2RGB);
cv::Mat hed = rgb2hed(mt);
std::vector<cv::Mat> v_hed;
split(hed , v_hed);
cv::Mat h = v_hed[0];//提取Hematoxylin通道
cv::Mat e = v_hed[1];//提取Eosin通道
cv::Mat d = v_hed[2];//提取DAB通道
}