create an example of red rose in matlab in matlab

Here is a simple code to create an example of red rose using MATLAB:

main.m
% create a 2D matrix with zeros
img = zeros(200, 200, 3, 'uint8');

% set the center of the image to red
img(100, 100, 1) = 255;

% create a circle around the center using the equation of a circle
for row = 1:200
    for col = 1:200
        if ((row-100)^2 + (col-100)^2) < 400 % radius 20
            img(row, col, 1) = 255;
            img(row, col, 2) = 0;
            img(row, col, 3) = 0;
        end
    end
end

% show the image
imshow(img);
449 chars
20 lines

This code creates a 2D matrix with zeros and sets the center pixel to red. Then it creates a circle around the center pixel using the equation of a circle and sets the color of those pixels to red as well. Finally, it displays the resulting image using the imshow function.

The resulting image will be a red rose with a diameter of 40 pixels.

related categories

gistlibby LogSnag