Ask Your Question

saving a frame using imwrite

asked 2013-02-15 04:44:27 -0500

engine gravatar image

Hi! I wrote a code to calcul the mean value and the standard deviation of multiple images, the code works fine I can see the standard deviation and the mean using imshow, but when I try to save them I get a black frame for the deviatframe here is the code :

cv::Mat frame,frame32f;
char filename[40];
cv::Mat mean;
const int count =4;
const int width  = 1920;
const int height = 1080;
cv::Mat resultframe = cv::Mat::zeros(height,width,CV_32FC3);
cv::Mat deviationframe = cv::Mat ::zeros(height,width,CV_32FC3);

cv::Mat temp = cv::Mat ::zeros(height,width,CV_32FC3);
for(int i = 1 ; i<= count; i++){
    frame = imread(filename,CV_LOAD_IMAGE_COLOR);
    frame.convertTo(frame32f,CV_32FC3 );
    resultframe +=frame32f;
resultframe *= (1.0/count);
for(int j =1; j<count; j++){
    frame = imread(filename,CV_LOAD_IMAGE_COLOR);
    temp =(frame32f - resultframe);
    deviationframe+= temp.mul(temp);
deviationframe *= 1.0/(count -1);


deviationframe= deviationframe/15.96;
resultframe *= 1.0/255.0;
imshow("mean ",resultframe);
imshow("deviation frame ",deviationframe);

return 0;

} as I said Ican save the mean file without any problem but the deviation ????? thanks in advance

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-02-15 09:13:08 -0500

unxnut gravatar image

Are you sure that you get a black frame. If it shows just the deviation from the original, it could be very small values that will appear to be black. Do you have access to some tool where you can examine the pixel values? Or better still, if you can apply histogram equalization on the image and see the result. One of such tools is the venerable xv (open source).

edit flag offensive delete link more


well you're right I opened it with SCILAB and the maximum Value is 9 and min is 0, I tried to multiply it with 255 in didn't really help

engine gravatar imageengine ( 2013-02-15 09:36:31 -0500 )edit

I multiple it with 100 and I can see the picture but the color are so wrong anyidea what should be the right factor ??

engine gravatar imageengine ( 2013-02-15 10:02:53 -0500 )edit

Can you do histogram equalization? That will typically be the best option. Otherwise, if you multiply by an arbitrary number, you may need to clip it at the top. Another option will be to find the max value (using minMaxLoc) and multiply the pixels by (255/max_value).

unxnut gravatar imageunxnut ( 2013-02-15 10:51:51 -0500 )edit

answered 2013-02-15 15:02:47 -0500

krishna gravatar image

Multiply it with 255 or actually there is no need to multiply by 1 / 255 at ( resultframe *= 1.0/255.0;)

edit flag offensive delete link more



This is incorrect. Multiplying by 255 will give you a number larger than 255 for an 8-bit image and you will lose information because of overflow.

unxnut gravatar imageunxnut ( 2013-02-15 15:14:50 -0500 )edit

I agress with unxnut and I did it before but I got only a whit frame

engine gravatar imageengine ( 2013-02-16 04:07:37 -0500 )edit

Question Tools


Asked: 2013-02-15 04:44:27 -0500

Seen: 2,162 times

Last updated: Feb 15 '13