Open In App

Draw Switzerland 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. RGB image representation: The RGB color model is an additive color model in which red, green and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue. Consider an RGB image array ‘I’ then,

Approach:



Below is the implementation: 




% matlab code to draw Switzerland flag
   
I = zeros(30, 50, 3);
% here image is of class ‘uint8’, the range of values
% that each colour component can have is [0 – 255] 
I = uint8(I); 
%painting the whole image red
I(:, :, 1) = 255; 
   
%white bar
I(5:25, 22:28, 1:3) = 255;
   
%white column
I(12:18, 10:40, 1:3) = 255;
   
% show the image formed
imshow(I);

Output:



Article Tags :