# How can I get the intensity sum of a circular region around a particular pixel?

41 views (last 30 days)
Happy PhD on 4 Feb 2021
Edited: Jan on 8 Feb 2021
I have two regions of light, in circles for which i want to calculate the intensity of region 1 (center circle) and region 2 (outher ring, for which i want to substract this center circle to only get the intensity only in the outher ring.).
How can i do this?
sum(sum(Img)) gives the total pixel intensity of the whole picture, but i want to know the different regions contributions.
According to my analysis my center circle have a high amplitude (dynamic range), while my outher ring region is very low in amplitude but is spread out within a larger area. I want to double check that big part of my measured intensity is distributed within this larger low amplitude region (noise region) compared to my high peak but small center circle.
Many thanks for any help.
##### 2 CommentsShowHide 1 older comment
Happy PhD on 4 Feb 2021
Edited: Happy PhD on 4 Feb 2021
Is this the intensity inside the cirle or outside?
Yes, well I manually set the center of the mage. the regions im looking at are pretty ccircular.

Jan on 4 Feb 2021
If you do have the position of the center and the radius already:
% Assuming that img is a 2D matrix/a grey scale image:
img = rand(640, 480);
x = 170; % Position of center
y = 400;
h = size(img, 1);
w = size(img, 2);
mask = ((1-x:h-x).' .^2 + (1-y:w-y) .^2) <= r^2;
Jan on 8 Feb 2021
Edited: Jan on 8 Feb 2021
You do see the code. Then you can simply try it:
img = zeros(10, 10);
x = 6; % Position of center
y = 4;
[h, w] = size(img);
mask = ((1-x:h-x).' .^2 + (1-y:w-y) .^2) <= r^2;
disp(img)
Maybe you want < instead of <=, but both use the inside of the circle. The outside would be > or >=.
Another way to find out, if this is the inside or outside: Increse the radius until the complete image is covered, e.g. r=1e6. Then you will get the sum over all existing pixels, if it is the inside of the circle, or 0 if it is the outside.
Or calculate the output for two different radii, r1 < r2. If the output is smaller for the smaller radius, you can be sure, that the algorithm measures the inside of the circle.

### Categories

Find more on Annotations in Help Center and File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!