Commit e779e276 authored by Tadej Borovšak's avatar Tadej Borovšak

Storing changes

parent 099ec620
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
static Mat
histogram (Mat const &img,
Mat const &kernel,
int bins)
{
int sizes[] = {bins, bins, bins};
Mat hist (3, sizes, CV_32F, Scalar::all (0));
Mat tmp;
img.convertTo (tmp, CV_8UC3, bins - 1);
float const *ptr_k = kernel.ptr<float> ();
Vec3b const *ptr_t = tmp.ptr<Vec3b> ();
int n = img.rows * img.cols;
for (int i = 0; i < n; i++)
hist.at<float> (ptr_t[i][0], ptr_t[i][1], ptr_t[i][2]) += ptr_k[i];
return hist;
}
int
main (void)
{
Mat img = (Mat_<Vec3b>(3,2) <<
Vec3b (0, 1, 2), Vec3b (3, 4, 5),
Vec3b (6, 7, 0), Vec3b (1, 0, 3),
Vec3b (4, 5, 6), Vec3b (7, 0, 1));
cout << img << endl;
img.convertTo (img, CV_32FC3, 1.0 / 7);
cout << img << endl;
Mat kernel = (Mat_<float> (3, 2) <<
0.5, 1.0, 0.5,
0.4, 0.9, 0.3);
kernel /= sum (kernel)[0];
cout << kernel << endl;
Mat hist = histogram (img, kernel, 4);
cout << hist.at<float> (0, 0, 1) << endl;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment