how to calculate intensity

Asked by Elysi Cochin

Elysi Cochin (view profile)

on 6 Feb 2013
Accepted Answer by Walter Roberson

Walter Roberson (view profile)

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

http://img89.imageshack.us/img89/1788/bdipt.png

Products

No products are associated with this question.

Walter Roberson (view profile)

Answer by Walter Roberson

Walter Roberson (view profile)

on 6 Feb 2013

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

Walter Roberson

Walter Roberson (view profile)

on 7 Feb 2013

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
```
Elysi Cochin

on 9 Feb 2013

thank u sir...

Image Analyst

Image Analyst (view profile)

on 9 Feb 2013

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;
```

Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi