Draw Sudan Flag using MATLAB

In Digital image processing, a colored image is represented in a 3-Dimensional matrix. Image can be represented in various color models such as RGB (Red, Green, Blue) model, HSV (Hue, Saturation, Value) model, YIQ (Luminance-Inphase Quadrature) model, CMYK (Cyan, Magenta, Yellow, Black) model. Generally, an image is represented in the RGB model. The first channel of the matrix is Red, the second channel is the Green and the third channel is Blue.

Approach to draw Sudan Flag:

  • Create a zero matrix of 300X600X3.300 is the number of rows, 600 is the number of columns and 3 represent RGB color channel. Fill the matrix with (255, 255, 255). 255 represent white pixel and 0 represent black pixel.
    img(:, :, :)=255
  • Fill the matrix with crimson color(210, 16, 42) between rows from 1 to 100 and between columns from 151:600.
  • Fill the matrix with black(0, 0, 0) between rows from 200 to 300 and between columns from 151:600.
  • After these operations, our image looks like this

  • Now, we have to draw one upper triangle and one lower triangle.
  • For lower triangle, from row 1 to 150 and column 1 to 150 fill the matrix with green color(0, 114, 14)
  • Similarly, for upper triangle, from row 150 to 300 and column 1 to 150 fill the matrix with green color(0, 114, 14)

Implementation is given below:





% MATLAB code to draw Sudan flag
% initialising a zero matrix of 300X600X3
img=uint8(zeros(300, 600, 3));
img(:, :, :)=255;
%Red Color
img(1:100, 151:600, 1)=210;
img(1:100, 151:600, 2)=16;
img(1:100, 151:600, 3)=42;
%black Color 
img(200:300, 150:600, :)=0;
% Lower Triangle
for i=1:150
    for j=1:150
            img(i, j, 1)=0;
            img(i, j, 2)=114;
            img(i, j, 3)=41;
            img(i, j, 1)=210;
            img(i, j, 2)=16;
            img(i, j, 3)=42;
% Upper Triangle
for i=150:300
    for j=1:150
            img(i, j, 1)=0;
            img(i, j, 2)=114;
            img(i, j, 3)=41;
            img(i, j, :)=0;            
% displaying the matrix as image
figure, imshow(img);


Output :

My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.