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 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,

- I(:, :, 1) represents the Red colour plane of the RGB image
- I(:, :, 2) represents the Green colour plane of the RGB image
- I(:, :, 3) represents the Blue colour plane of the RGB image

**Approach:**

- Make a 3 order zero matrix of dimensions 30 X 50 X 3. 30 denotes the number of pixels for rows, 50 denotes number of pixels for columns and 3 denotes the color coding in RGB format.
- Paint the complete image in red. RGB code for red is (255, 0, 0)
- Make the horizontal white bar. RGB code for white is (255, 255, 255)
- Make the vertical white bar.

**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); ` |

*chevron_right*

*filter_none*

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

## Recommended Posts:

- Draw Sweden Flag using matlab
- How to draw Japan flag using MATLAB
- Draw Kuwait Flag using MATLAB
- Draw Sudan Flag using MATLAB
- Draw Indian Flag using matlab
- Draw Seychelles Flag using MATLAB
- Draw Austria flag using Matlab
- Draw Bangladesh Flag Using Matlab
- Draw Thailand Flag Using MATLAB
- Tr0ll 3 Walkthrough of Check the Flag or CTF Problem
- MATLAB | Converting a Grayscale Image to Binary Image using Thresholding
- LSB based Image steganography using MATLAB
- Plot a circle using centre point and radius in MATLAB
- Matlab | Edge Detection of an image without using in-built function
- Create Mirror Image using MATLAB
- How to vertically flip an Image using MATLAB
- Matlab program to rotate an image 180 degrees clockwise without using function
- MATLAB - Image Edge Detection using Prewitt Operator from Scratch
- MATLAB - Image Edge Detection using Sobel Operator from Scratch
- MATLAB - Image Edge Detection using Robert Operator from Scratch

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.