How can I get the intensity sum of a circular region around a particular pixel?
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Jan
il 4 Feb 2021
Did you determine the pixel position of the center and the radius of the ring already? Is the ring a circle or geometrically distorted?
Risposta accettata
Jan
il 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;
r = 31; % Radius
h = size(img, 1);
w = size(img, 2);
mask = ((1-x:h-x).' .^2 + (1-y:w-y) .^2) <= r^2;
Result = sum(img(mask), 'all')
3 Commenti
Jan
il 8 Feb 2021
Modificato: Jan
il 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;
r = 3; % Radius
[h, w] = size(img);
mask = ((1-x:h-x).' .^2 + (1-y:w-y) .^2) <= r^2;
disp(mask)
img(mask) = 2;
disp(img)
Result = sum(img(mask), 'all')
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Image Processing Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!