C++ Create and Save OpenCV 16bit image pixelwise -


i create 16bit png-image opencv setting pixel values manually noise generation. tried following:

cv::mat img16(window_y, window_x, cv_16uc3); // create 16 bit mat  float val, new_value; float noise = 3.1343; // randomly generated randomizer in (0..255) (int x = 0; x < window_x; x++) {     (int y = 0; y < window_y; y++) {         (int = 0; < 3; i++) {             // value cv_8uc3-mat             val = img.at<cv::vec3b>(y,x)[i];              // add noise , scale 16bit             new_value = (val + noise)*255;              // avoid overflow @ 2^16-1             if (new_value > 65535) {                  new_value = 65535;             }             // set value 16bit mat             img16.at<cv::vec3s>(y,x)[i] = (short) new_value;         }     } } // write png file, since png supports 16 bit cv::imwrite(file + ".png", img16); 

what output seems 16 bit:

 $ identify output.png   output.png png 128x128 128x128+0+0 16-bit pseudoclass 65536c 

but shows monotone grey (#808080) while expect heterogeneous image. what's wrong it?

whenever see writing per-pixel loops in opencv, - hold on, , try find builtin instead.

mat ocv=mat(200,200,cv_16uc3); // can save 16bit *unsigned* png or tif therng().fill(ocv,rng::uniform,0,65535); 

enter image description here


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -