c++ - Normalising an image in opencv -


i have rgb image stored in mat datastructure. converting image grayscale using cvtcolor function in opencv. after trying normalise image range [0,1]. using default normalize function of opencv. check correctness, tried printing pixel values , equate matlab values(matlab values in range [0,1]). values differ lot. me make both results same. below opencv , matlab codes.

mat img1 = imread("d:/input.png", cv_load_image_color); cvtcolor(img1, img1, cv_bgr2gray); img1.convertto(img1, cv_32fc1); cv::normalize(img1, img1, 0.0, 1.0, norm_minmax, cv_32fc1); (int = 0; < img1.rows; i++) {     (int j = 0; j < img1.cols; j++)     {        cout << img1.at<float>(i, j) << endl;     } } 

matlab code:

 i=im2double(imread('input.png'));  gi=rgb2gray(i);  display(gi) 

i don't think want normalize here. matlab conversion rgb2gray uses equation: 0.2989 * r + 0.5870 * g + 0.1140 * b. there's no expectation have minimum value of 0.0 or maximum value of 1.0 in output greyscale image. expect 0 , 1 if had pure white (255,255,255) , pure black (0,0,0) pixels.

try this:

img *= 1./255; cvtcolor(img, img, cv_bgr2gray); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -