ri라는 double형 cv::Mat를 imshow()함수로 출력한다.
cv::Mat mat = ri->getClone(); // ri = cv::Mat(h, w, cv::DataType<double>::type)
std::cout << "channels : " << mat.channels() << std::endl; // 1
std::cout << "type : " << mat.type() << std::endl; // 6
std::cout << "depth : " << mat.depth() << std::endl; // 6 CV_64F
int h = mat.rows;
int w = mat.cols;
double t_max = DBL_MIN;
double t_min = DBL_MAX;
Concurrency::parallel_for(0, h, [&](int y)
{
for (int x = 0; x < w; x++)
{
if (mat.at<double>(y, x) < 0) continue; // error 값
if (mat.at<double>(y, x) > t_max) t_max = mat.at<double>(y, x);
if (mat.at<double>(y, x) < t_min) t_min = mat.at<double>(y, x);
}
});
double scale = 255. / (t_max - t_min);
cv::Mat sumImage(mat.rows, mat.cols, CV_8UC3); // 3channels
sumImage.setTo(cv::Scalar(0,200,0));
Concurrency::parallel_for(0, h, [&](int y)
{
for (int x = 0; x < w; x++)
{
if (mat.at<double>(y, x) < 0) continue; // error 값
unsigned char intensity = cv::saturate_cast<uchar>((mat.at<double>(y, x) - t_min) * scale);
sumImage.at<cv::Vec3b>(y, x)[0] = intensity;
sumImage.at<cv::Vec3b>(y, x)[1] = intensity;
sumImage.at<cv::Vec3b>(y, x)[2] = intensity;
}
});
cv::imshow("hello", sumImage);
cv::waitKey(0);
댓글 없음:
댓글 쓰기