expand selection in image to include all pixels from x, y by 20 pixels radially in matlab

To expand the selection in an image to include all the pixels radially from a specified point, you can use the strel function to create a circular structuring element and the imdilate function to perform the dilation operation.

Here's an example of how to do it:

main.m
% read the image
img = imread('image.png');

% specify the center point (x,y)
x = 100;
y = 100;

% create a circular structuring element with radius of 20 pixels
se = strel('disk', 20);

% create a binary mask for the structuring element centered on the point (x,y)
mask = false(size(img,1), size(img,2));
mask(y,x) = true;
mask = imdilate(mask, se);

% apply the mask to the original image
img(mask==0) = 0;

% show the resulting image with the selection expanded
imshow(img);
478 chars
21 lines

In this code, we first read the image and specify the center point (x and y). Then, we create a circular structuring element using the strel function with a radius of 20 pixels. Next, we create a binary mask for the structuring element centered on the point (x and y) using the imdilate function. This mask will have a value of true inside the structuring element and false outside. Finally, we apply the mask to the original image by setting all pixels outside the mask to zero, and show the resulting image with the selection expanded.

gistlibby LogSnag