Draw Kuwait 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
- Make a 3 order zero matrix of dimensions 300X500X3. 300 denotes the number of pixels for rows, 500 denotes number of pixels for columns and 3 denotes the color coding in RGB format. The image starts completely black because for all the pixels the color code is (0, 0, 0).
- Paint the horizontal bar between rows 1 to 100, and between columns 101 to 500 green. The color code of green in Kuwait’s flag is (0, 122, 61).
- Paint the horizontal bar between rows 101 to 200, and between columns 101 to 500 white. The color code of white is (255, 255, 255).
- Paint the horizontal bar between rows 201 to 300, and between columns 101 to 500 red. The color code of red in Kuwait’s flag is (206, 17, 38)
- At this point we have an image which looks like this:
Now we have to draw 2 triangles.
- For the upper green triangle. In the matrix with rows from 1 to 100, and columns from 1 to 100, paint the upper right triangle green.
- For the lower red triangle. In the matrix with rows from 201 to 300, and columns from 1 to 100, paint the lower right triangle red.
Below is the implementation :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course