Jiwon-Hwang / All-About-Programming

Curiosity Collection (Grammar, Configuration, CS..)
0 stars 0 forks source link

Convert Arr2Mat, Mat2Arr / 16bit(short) to 8bit(unsigned char) / CV_type #24

Open Jiwon-Hwang opened 2 years ago

Jiwon-Hwang commented 2 years ago

Convert Arr to Mat

short* psImage;
Mat psImage_mat(nWidth, nHeight, CV_16SC1, psImage);

Convert Mat to Arr

short* psImage_arr = (short*)psImage_mat.data;

Convert 16bit(short) to 8bit(unsigned char)

normalization


Mat img(row, col, CV_16SC1); // 16bit(short)
Mat img_8UC1 = img.clone();

// get min, max double minVal; double maxVal; Point minLoc; Point maxLoc; minMaxLoc(img, &minVal, &maxVal, &minLoc, &maxLoc);

// normalization img_8UC1 -= minVal; img_8UC1.convertTo(img_8UC1, CV_8U, 255.0 / (maxVal - minVal)); // 8bit(uchar)

Jiwon-Hwang commented 2 years ago

CV_type

Mat의 요소가 어떤 타입의 데이터인지 지정

Jiwon-Hwang commented 2 years ago

normalize (0~1로 정규화)

cv::normalize(src, dst, 0, 1, NORM_MINMAX, CV_8UC1);