Open In App

Draw Seychelles Flag using MATLAB

A colored image can be represented as a 3 order matrix. The first order is for the rows, the second order is for the columns and the third order is for specifying the color of the corresponding pixel. Here we use the RGB color format, so the third order will take 3 values of Red, Green and Blue respectively. The values of the rows and columns depending on the size of the image.

Prerequisite: RGB image representation



Approach:

Implementation:






% MATLAB code to draw Seychelles flag
  
% initialising a zero matrix of 300X600X3 
im=uint8(zeros(300, 600, 3))+255;
  
% blue
for i = 1:300
    for j = 1:600
        im(i, j, 1) = 0;
        im(i, j, 2) = 63;
        im(i, j, 3) = 135;
    end 
end
  
% yellow
for i = 1 : 300
    for j = 1 : 600
        m = round(abs((i-300)/(j-1)), 2);
        if m <= 1.55
            im(i, j, 1) = 252;
            im(i, j, 2) = 216;
            im(i, j, 3) = 86;
        end
    end 
end
  
% red
for i = 1 : 300
    for j = 1 : 600
        m = round(abs((i-300)/(j-1)), 2);
        if m <= 0.75
            im(i, j, 1) = 214;
            im(i, j, 2) = 40;
            im(i, j, 3) = 40;
        end
    end 
end
  
% white
for i = 1 : 300
    for j = 1 : 600
        m = round(abs((i-300)/(j-1)), 2);
        if m <= 0.36
            im(i, j, 1) = 255;
            im(i, j, 2) = 255;
            im(i, j, 3) = 255;
        end
    end 
end
  
% green
for i = 1 : 300
    for j = 1 : 600
        m = round(abs((i-300)/(j-1)), 2);
        if m <= 0.15
            im(i, j, 1) = 0;
            im(i, j, 2) = 122;
            im(i, j, 3) = 61;
        end
    end 
end
  
% displaying the matrix as an image
figure, imshow(im);

Output :


Article Tags :