Ask Your Question
0

OpenCV (C++) - whitenning transformation on a color image

asked 2017-03-09 19:24:33 -0600

mhaghighat gravatar image

Is there a built-in function to apply a whitening transformation on a cv::Mat with 3 channels? I want the image to have a zero mean and a unit variance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-10 01:04:16 -0600

LBerger gravatar image

No I don't think so. You can do like that :

{
Mat x = imread("f:/lib/opencv/samples/data/lena.jpg", IMREAD_COLOR);

Mat m,s;
x.convertTo(x,CV_32F);
meanStdDev(x, m, s);
vector<Mat> xc;
split(x, xc);
for (int i = 0; i<xc.size(); i++)
{
    cout << m.at<double>(i, 0) << "\t" << s.at<double>(i, 0) << "\n";
    xc[i] = (xc[i]- m.at<double>(i, 0)) / s.at<double>(i,0);
}
merge(xc,x);
meanStdDev(x, m, s);
for (int i = 0; i<m.rows; i++)
    cout<< m.at<double>(i,0)<<"\t"<< s.at<double>(i,0)<<"\n";

}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-03-09 19:24:33 -0600

Seen: 803 times

Last updated: Mar 10 '17