MATLAB: How to get the values of a circular region around a particular pixel

finger detection

How can I get the values of a circular region around a particular pixel?

Best Answer

Assuming:
  • your image is grayscale and is called img;
  • the central pixel is at column x and row y;
  • the radius of the circle is r;
  • you do not require weighting at the rim of the circle - that is, each pixel is either entirely inside or entirely outside the circle;
then you can do something like this
[xgrid, ygrid] = meshgrid(1:size(img,2), 1:size(img,1));
mask = ((xgrid-x).^2 + (ygrid-y).^2) <= r.^2;
values = img(mask);
where values will have a column vector containing the values in the circular region.