how to calculate intensity

I really appreciate your help and I would be so grateful if you help me with this?,
how to calculate, the difference between the number of pixels in a block and the ratio of the sum of pixel intensities in the block to the maximum in the block
i wanted to substitute the values in the equation in the link below.....
please do reply.....

 Accepted Answer

I = rgb2gray( im2double( YourImage) );
T = M(x : x+M-1, y : y+M-1);
sum(T(:))
max(T(:))
and I'll leave you to work out the ratio.

9 Comments

thank u sir.... sir what does that x and y value denote.... is it row and coulmn..... please reply sir.....
It denotes the same thing that is in the formula.
This is a common source of confusion. In the formula they have I(x,y) where x is the horizontal index. But in MATLAB, with arrays, the first index is the vertical index. So it's something you always have to watch out for. Fortunately since you're going over all pixels, it doesn't really matter except when you get to the end of a row or columns. You need to calculate
[rows columns numberOfColorChannels] = size(I);
then the first index (what they call x) must go from 1 to rows, not 1 to columns (which you'd think would be the last x value going by the name "x").
sir, when i did like this.... i'm getting error... this is what i did....
[filename pathname] = uigetfile('*.png','Select An Image');
yourImage = imread([pathname filename]);
I = rgb2gray( im2double( yourImage ) );
[x y] = size(I);
T = M(x : x+M-1, y : y+M-1);
sum(T(:))
max(T(:))
This is the error i'm getting.... how to rectify it sir.....
??? Index exceeds matrix dimensions.
Error in ==> Untitled5 at 9
T = M(x : x+M-1, y : y+M-1);
please do reply sir.....
The line
T = M(x : x+M-1, y : y+M-1);
should have been
T = I(x : x+M-1, y : y+M-1);
sir i changed the above line..... but its still showing that same error.....
If your blocks are to slide G pixels at a time, e.g., G = 1
for x = 1 : G : size(I,1) - M + 1
for y = 1 : G : size(I,2) - M + 1
B = M(x : x+M-1, y : y+M-1);
P = sum(B(:));
Q = max(B(:));
ratio = .... a function of P and Q
end
end
thank u sir...
Of course you could do this all in one to three lines with a vectorized approach using conv2() and imdilate(), like this (untested):
blurredImage = -conv2(yourImage, ones(M)/M^2, 'same') + M^2;
maxImage = imdilate(yourImage, true(M));
BDIP = blurredImage ./ maxImage;

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!