make square image with a circle in the middle, amataure code in matlab

main.m
% Create a black square image
image_size = 500;
square_image = zeros(image_size, image_size);

% Find the center of the image
center_x = image_size / 2;
center_y = image_size / 2;

% Create a meshgrid to represent the coordinates of the image
[X, Y] = meshgrid(1:image_size, 1:image_size);

% Define the radius of the circle
radius = image_size / 4;

% Create a binary mask for the circle using distance from center
circle_mask = (X - center_x).^2 + (Y - center_y).^2 <= radius.^2;

% Assign white color (255) to the circle region in the square image
square_image(circle_mask) = 255;

% Display the square image with circle
imshow(square_image);
646 chars
23 lines

related categories

gistlibby LogSnag