Ask Your Question
0

Energy computation of DCT of image +

asked 2017-12-16 01:39:20 -0600

MariGeek gravatar image

updated 2017-12-18 08:17:16 -0600

I am interested to know Energy of low and high frequency component of dct (discrete cosine transform) of image. Here, i found energy computation of signal

I cannot find energy computation of low and frequency component of dct from image. so i used the energy computation of signal as shown formula below.

Energy = Sum (Amplitude * Amplitude )

Below are the original, dct image and its energy computed from above formula.

Original Image

image description

dct of above image.

image description

Then, i am using upper quadrant of image as low frequency and bottom corner quadrant of image is high frequency compoent.

And their energy is as follows: 21.391 , 11.2572

My question is how to exactly find energy of frequency from DFT or DCT? Or Same formula of energy computation is used for image and signal processing?

I need paper reference where formula of energy computation is given.

Kindly, help me to understand. Thanks

edit retag flag offensive close merge delete

Comments

1

Energy is proportional to frequency, in terms of light anyway.

sjhalayka gravatar imagesjhalayka ( 2017-12-16 10:26:09 -0600 )edit
1

Is your question about opencv or mathematics?

LBerger gravatar imageLBerger ( 2017-12-16 11:24:25 -0600 )edit

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.

sjhalayka gravatar imagesjhalayka ( 2017-12-16 16:26:04 -0600 )edit

My question is about in Opencv

MariGeek gravatar imageMariGeek ( 2017-12-17 23:11:50 -0600 )edit

@sjhalayka, yes i am using discrete Image, And thank you for clearing my understanding.

MariGeek gravatar imageMariGeek ( 2017-12-17 23:12:53 -0600 )edit

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 gravatar imageMariGeek ( 2017-12-18 04:26:28 -0600 )edit

@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.

sjhalayka gravatar imagesjhalayka ( 2017-12-19 14:56:08 -0600 )edit

I need a reference paper where the formula is given. because i have to add reference in my thesis.

MariGeek gravatar imageMariGeek ( 2017-12-22 02:45:00 -0600 )edit

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.

sjhalayka gravatar imagesjhalayka ( 2017-12-22 10:02:18 -0600 )edit

2 answers

Sort by » oldest newest most voted
1

answered 2017-12-22 13:51:25 -0600

sjhalayka gravatar image

updated 2017-12-22 20:06:44 -0600

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;
}
edit flag offensive delete link more

Comments

Why did you do entropy = - entropy ?

MariGeek gravatar imageMariGeek ( 2017-12-22 23:41:55 -0600 )edit

The probability variable is less than 1, so the calls to log() return negative numbers. After adding all of those negative numbers up, you must negate the entropy so that it becomes a positive number. This is why there's a negative sign in the entropy formula found on this page: https://en.wikipedia.org/wiki/Entropy...

sjhalayka gravatar imagesjhalayka ( 2017-12-23 07:34:37 -0600 )edit

Note: the entropy measurement is the average nats per message (pixel). You can divide the natural entropy by ln(2) to get the average bits per message; the binary entropy. The average bits is the number of bits needed to encode each message.

Like, if you have 8 equiprobable messages, the binary entropy simplifies to be S = ln(8)/ln(2) = 3. This is intuitive: it takes 3 bits (binary digits) to encode the decimal value 8.

The binary entropy isn’t always a whole number, and if you have difficulty believing in the binary entropy as a real number, you can always perform the ceiling function on the binary entropy, to get a whole number of bits.

sjhalayka gravatar imagesjhalayka ( 2017-12-23 15:44:57 -0600 )edit

ok so far, i found this energy formula. https://en.wikipedia.org/wiki/Parseva...

MariGeek gravatar imageMariGeek ( 2017-12-24 20:35:44 -0600 )edit

According to Parseval's theorem, https://en.wikipedia.org/wiki/Parseva.... I computed energy = 1/ 2 (Sum ( amplitude * amplitude)) then my energy is every time 0. but when I do energy = Sum (amplitude* amplitude) then I get energy. So, I am pretty confuse what really energy is for Image in DCT image.

MariGeek gravatar imageMariGeek ( 2017-12-24 20:45:18 -0600 )edit

@MariGeek -- Can you post your code somewhere, like on GitHub?

sjhalayka gravatar imagesjhalayka ( 2017-12-24 21:19:20 -0600 )edit

i tested your entropy code on dark image. dark image.

My entropy is 5.15207 which is same for my image attached with this question. Entropy for low contrast or dark image should be low. But it is not low. Why so?

MariGeek gravatar imageMariGeek ( 2017-12-25 04:22:18 -0600 )edit

Also, i tested entropy from Matalb function E = entropy(I) and its entropy is 4.7701 while good contrast image entropy is 7.4329. so i will better use matlab function and will see its description and will try to find reference paper for it.

MariGeek gravatar imageMariGeek ( 2017-12-25 04:36:29 -0600 )edit

It all boils down to how many distinct pixel values there are in the image, which is why I use a std::map to count the number of times that each distinct pixel value shows up in the image. Dark, low contrast, the image still contains a lot of distinct pixel values, and that is reflected by the entropy measurement. You can also think of entropy as a measure of compressibility -- if the image contains all pixels having a value of b: 0, g: 0, r: 0, the entropy is zero (the sole probability is 1) -- the image is maximally compressible.

If Matlab calculates a different entropy, then it's wrong; calculate the entropy of a totally black image, it better be zero.

sjhalayka gravatar imagesjhalayka ( 2017-12-25 07:52:36 -0600 )edit

i tried this image blakcimage to estiate the entropy from your code. it entropy is 2.7... , which suppose to be 0. But now i do not feel like entropy is a better way find either image is low contrate or not .

Do you know any other approach to find entropy?

MariGeek gravatar imageMariGeek ( 2017-12-25 20:40:34 -0600 )edit
0

answered 2017-12-18 08:32:58 -0600

LBerger gravatar image

updated 2017-12-18 09:01:35 -0600

berak gravatar image

Usually I say google is your friend but today Duckduck go is better :

Discrete Cosine Transform - Imperial College London

edit flag offensive delete link more

Comments

i have googled many times but found different formula used for DCT in signal processing. i cannot find energy computation in DCT for image.

MariGeek gravatar imageMariGeek ( 2017-12-22 02:49:58 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-12-16 01:39:20 -0600

Seen: 2,123 times

Last updated: Dec 22 '17