Ask Your Question
0

saving a frame using imwrite

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

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++){
    sprintf(filename,"d:\\BMdvideos\\images\\image%d.tiff",i);
    frame = imread(filename,CV_LOAD_IMAGE_COLOR);
    frame.convertTo(frame32f,CV_32FC3 );
    resultframe +=frame32f;
    frame.release();
}
resultframe *= (1.0/count);
for(int j =1; j<count; j++){
    sprintf(filename,"d:\\BMdvideos\\images\\image%d.tiff",j);
    frame = imread(filename,CV_LOAD_IMAGE_COLOR);
    frame.convertTo(frame32f,CV_32FC3);
    temp =(frame32f - resultframe);
    deviationframe+= temp.mul(temp);
}
deviationframe *= 1.0/(count -1);



cv::sqrt(deviationframe,deviationframe);
cv::imwrite("blblblb.tif",deviationframe);
cv::imwrite("mean.tif",resultframe);

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

waitKey(0);
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
1

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

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

Comments

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 -0600 )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 -0600 )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 -0600 )edit
0

answered 2013-02-15 15:02:47 -0600

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

Comments

2

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 -0600 )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 -0600 )edit

Question Tools

Stats

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

Seen: 2,329 times

Last updated: Feb 15 '13