Don't forget to get the entropy of an image. It goes to show that an image is a discrete signal consisting of pixels (messages). You will note that we use the same entropy calculation as Shannon; it's called the Shannon entropy.
So, if the entropy calculation for a signal and for an image are the same, then so must the energy calculations be the same, or at least proportionate to each other like: intensity = c * amplitude^2, where c is some constant. The intensity of one pixel is 0 through 255 times some constant number of red photons, plus 0 through 255 times some constant number of blue photons, plus 0 through 255 times some constant number of green photons, per second per unit area. The intensity is also handily known as power per unit area.
For example, here is the C++ code to calculate the entropy of a greyscale image:
#include <opencv2/opencv.hpp>
using namespace cv;
#pragma comment(lib, "opencv_world331.lib")
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(void)
{
Mat frame = imread("puppets.png", CV_LOAD_IMAGE_GRAYSCALE);
if (frame.empty())
{
cout << "Error loading image file" << endl;
return -1;
}
map<unsigned char, size_t> pixel_map;
for (int j = 0; j < frame.rows; j++)
for (int i = 0; i < frame.cols; i++)
pixel_map[frame.at<unsigned char>(j, i)]++;
double entropy = 0;
for (map<unsigned char, size_t>::const_iterator ci = pixel_map.begin(); ci != pixel_map.end(); ci++)
{
double probability = ci->second / static_cast<double>(frame.rows*frame.cols);
entropy += probability * log(probability);
}
entropy = -entropy;
cout << entropy << endl;
return 0;
}
Also for example, here is the C++ code to calculate the entropy of a BGR image:
#include <opencv2/opencv.hpp>
using namespace cv;
#pragma comment(lib, "opencv_world331.lib")
#include <iostream>
#include <vector>
#include <map>
using namespace std;
class vector3b : public Vec3b
{
public:
inline bool operator<(const vector3b &right) const
{
if (right.val[0] > val[0])
return true;
else if (right.val[0] < val[0])
return false;
if (right.val[1] > val[1])
return true;
else if (right.val[1] < val[1])
return false;
if (right.val[2] > val[2])
return true;
else if (right.val[2] < val[2])
return false;
return false;
}
};
int main(void)
{
Mat frame = imread("puppets.png");
if (frame.empty())
{
cout << "Error loading image file" << endl;
return -1;
}
map<vector3b, size_t> pixel_map;
for (int j = 0; j < frame.rows; j++)
for (int i = 0; i < frame.cols; i++)
pixel_map[frame.at<vector3b>(j, i)]++;
double entropy = 0;
for (map<vector3b, size_t>::const_iterator ci = pixel_map.begin(); ci != pixel_map.end(); ci++)
{
double probability = ci->second / static_cast<double>(frame.rows*frame.cols);
entropy += probability * log(probability);
}
entropy = -entropy;
cout << frame.rows*frame.cols << endl;
cout << pixel_map.size() << endl;
cout << entropy << endl;
return 0;
}
Energy is proportional to frequency, in terms of light anyway.
Is your question about opencv or mathematics?
Correct me if I'm wrong, but the image is a discrete message, which is a concept that lies at the heart of information theory. So yeah, my guess is that it's the same computation.
My question is about in Opencv
@sjhalayka, yes i am using discrete Image, And thank you for clearing my understanding.
I need a paper reference where formula of energy computation in DFT or DCT is given. Can anyone ref me if someone know. thanks
@MariGeek -- I asked your question on https://www.gamedev.net/forums/topic/... and I got an answer back. You may want to check it out. They said that the energy is the sum (integral) of the amplitudes squared, which is what you were saying in the beginning. Oh, and the intensity is the amplitude squared.
I need a reference paper where the formula is given. because i have to add reference in my thesis.
I think any basic high school physics text has information about intensity and amplitude squared. I found this website to be handy: http://muchomas.lassp.cornell.edu/p21...
Maybe the author of that website can give you a reference, if you can find their email address.