Pixel values differ between opencv and matlab -


when displaying pixel values of image (a rgb image converted grayscale) using "display" function in matlab, found pixel values less 1 (all values between 0 , 1). whereas when same in opencv, getting higher values. why change in values happen ? open cv code , matlab code follows:

for (int = 0; < img1.rows; i++) {     (int j = 0; j < img1.cols; j++)     {         cout << (unsigned int)img1.at<uchar>(i, j) << endl;     } }  matlab code:  gi=rgb2gray(i); imshow(gi); 

sorry disappoint you. no 1 guarantees conversion of rgb gray-scale yield same result. there 2 reasons

  1. the conversion not mathematical correct formula rather subjective issue. on course of last 50 years few different standards (mainly color television supporting greyscale signals) written of how convert rgb gray level. different standards lead identical visible results, though actual values of pixels differ bit (~roughly 0.2%). can read more standards in wikipedia. example: 1 standard defines conversion of rgb gray while defines conversion of rgb yuv , taking y channel gray scale. there few other standards (preserving luminosity, intensity, contrast, etc). since preference of standards change on time, hard know how rgb gray implemented. here example of 3 different methods. open cv uses different method (0.299f*red + 0.587f*green + 0.114f*blue here) while matlab uses method (0.2989*red + 0.587*green + 0.1140*blue. here). note difference between opencv 0.299 , matlabs 0.2989. more information can found in answer (here)
  2. second reason - different floating point representation across hardware , software. floating point computation (regardless whether double or float) not precise , depends on specific hardware use, type of compiler witch build software , specific compiler directives. same mathematical calculation can yield different results on different computers or on same computer in 2 different programs. unfortunately not same results rgb gray conversion if round values range of [0..255] typically discrepancy of no more 2 levels. in 99.9% pixels same value , in others difference of 1. 2 rare , have never seen difference of 3, unless few sequential conversions rgb->xyz->hsv->yuv

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 -