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. Related SolutionsMATLAB: Can I calculate the amount of black and white pixels inside a freehand region The mask just tells you which pixels are in the region. To count the black pixels within the mask, you need to look at both in the region and the value in the original image. Something like this:nBlack1 = sum(sum(Image1 & ~origImage)) MATLAB: How to get the intensity sum of a circular region around a particular pixel 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 centery = 400;r = 31; % Radiush = 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') Related QuestionHow to blank data within a circleHow do you use roifill if the mask you have specifies all the pixels you want replacedHow to isolate certain part of imageHow to mask on roi areaPointing to a certain area and calculate the averageOverlay mask on sequence of mri images to mark out tumor ROI
Best Answer