Open In App

Draw Sweden 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 ans Blue respectively. The values of the rows and columns depends on the size of the image.

Prerequisite : RGB image representation

Approach :

Below is the implementation:




% matlab code to draw Sweden flag
  
I = zeros(300, 600, 3);
  
%painting the whole image blue
I(:, :, 3) = 255; 
  
%yellow bar
I(120:180, :, 1:2) = 255; I(120:180, :, 3) = 0;
  
%yellow column
I(:, 150:210, 1:2) = 255;I(:, 150:210, 3) = 0; 
  
%print the matrix as image
imshow(I) 

Output:

Article Tags :