Ask Your Question
0

Getting the std deviation of multiple pictures using Opencv

asked 2013-02-14 05:06:12 -0600

engine gravatar image

updated 2013-02-14 05:44:12 -0600

I'm trying to get the standard deviation of multiple pictures using, OpenCV, here what I've done :

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\opencv.hpp>

using namespace std;
using namespace cv;

int main() {
    cv::Mat frame,frame32f;
    char filename[40];
    cv::Mat mean;
    const int count = 273;
    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);
    for(int i = 1 ; i<= count; i++){
    //int i = 3;
    sprintf(filename,"d:\\BMdvideos\\images\\image%d.tiff",i);
    frame = imread(filename,CV_LOAD_IMAGE_COLOR);
    frame.convertTo(frame32f,CV_32FC3 );
    //cout << " frame type " << frame.type() << endl;
    //imshow(" frame32f" , frame32f);
    resultframe +=frame32f;
    //cout<< "rows number " << frame.rows<< std::endl;
    //cout<<"column number " << frame.cols<<std::endl;
    cout << " i = " << i<<endl;
    frame.release();
    }
    resultframe *= (1.0/count/255);
    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);
        deviationframe =(frame32f - resultframe);
        deviationframe= deviationframe.mul(deviationframe);
    }
    deviationframe = deviationframe /(count -1 );

    cv::sqrt(deviationframe,deviationframe);
    //deviationframe *= (1.0/255); doesn't change anything ? ? 
    imshow("mean ",resultframe);
    imshow("deviation frame ",deviationframe);
    waitKey(0);
    return 0;
}

when I see what I get the result frame "mean value" is correct but the std deviation is just wrong. any idea what I'm doing wrong, thanks in advance for help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-02-14 11:15:49 -0600

kabamaru gravatar image

updated 2013-02-14 11:16:58 -0600

Your code seems wrong: deviationframe= deviationframe.mul(deviationframe);

Should be something like:

bufferFrame =(frame32f - resultframe);
deviationframe += bufferFrame * bufferFrame;
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-14 05:06:12 -0600

Seen: 528 times

Last updated: Feb 14 '13