영상처리

OpenCV convertTo (16bit -> 8bit)

park__ 2024. 12. 11. 09:54

방법 1

		std::string str_img_path = "";
		cv::Mat img_16bit = cv::imread(str_img_path);
		cv::Mat img_8bit;
		img_16bit.convertTo(img_8bit, CV_8UC1, 256.0 / 65536.0);

 

방법 2

		std::string str_img_path = "";
		cv::Mat img_16bit = cv::imread(str_img_path);
		cv::Mat img_8bit;
		
		double min, max;
		cv::minMaxLoc(img_16bit, &min, &max);
		img_16bit = img_16bit - min;
		img_16bit.convertTo(raw_img_8bit, CV_8UC1, 256.0 / (max - min + 1));

 

2번째 방법을 사용하는게 16bit 영상에 대한 정보가 더 많이 남아 있을 확률이 높음.

'영상처리' 카테고리의 다른 글

AutoThreshold (Mean) C++  (0) 2024.12.11
AutoThreshold (MaxEntropy) C++  (0) 2024.12.11
AutoThreshold (Intermodes) C++  (0) 2024.12.11
AutoThreshold (IJDefault) C++  (0) 2024.12.10
Auto Threshold (Huang2) C++  (1) 2024.12.10