16位灰度图转8位
//16位灰度图转8位 static Mat Gray16To8(Mat &src, Mat &dst, int height, int width) { double minv = 0.0, maxv = 0.0; double* minp = &minv; double* maxp = &maxv; minMaxIdx(src, minp, maxp); ushort *p_src; uchar *p_dst; for (int i = 0; i < height; i++) { p_src = src.ptr<ushort>(i); p_dst = dst.ptr<uchar>(i); for (int j = 0; j < width; j++) { p_dst[j] = (p_src[j] - minv) / (maxv - minv) * 255; } } return dst; }