# Draw Countries Flags Using MATLAB

MATLAB makes the creation of flags with precise proportions and colors possible by utilizing its graphic tools and image-processing capabilities. Flags from different nations can be represented visually using MATLAB, an efficient programming language. Here, we'll look at how to draw several flags while showing their distinctive patterns and symbolism.

## Drawing the Indian Flag Using MATLAB

The tricolor Tiranga, also known as the national flag of India, has a navy blue Ashoka Chakra in the middle of three horizontal stripes of saffron, white, and green. To depict the nation's rich cultural and historical significance, it is necessary to faithfully reproduce these colors and proportions when drawing the Indian flag in MATLAB.

Approach:

• As a starting point for plotting, set up a figure.
• Define the flag's dimensions, normally 3:2 in width to height.
• Define the precise RGB values for saffron, white, green, and navy blue by the requirements for the Indian flag.
• Use the ' rectangle' function to create three rectangles, one for each of the flag's colors: saffron, white, and green.
• Using parametric equations, draw a circle and fill it with navy blue to represent the Ashoka Chakra in the middle of the white stripe.
• Use the command ' set (gca,' visible,'' off')' to hide the axes and depict the flag.

Implementation:

Output:

Saffron: The top band of the flag stands for bravery and selflessness. It is a rich, vivid orange color in the flag.

White: The center band represents purity, truth, and peace. To preserve the integrity of the flag, it is crucial to depict this white band precisely.

Green: The bottom band represents fertility, faith, and wealth. The flag has a deep, rich green color.

Ashoka Chakra: The navy blue Ashoka Chakra The Ashoka Chakra, located in the center of the white band, stands for the "wheel of the law" and denotes the nation's ongoing development. Each of its 24 spokes represents a different aspect of movement and life.

It is feasible to accurately display the object's intricate design and symbolism with MATLAB's image generation functions and precise color representation.

## Draw the Austria flag in Matlab.

Three horizontal stripes make up the "Bundesflagge," the name given to Austria's national flag. The center stripe is white, and the top and bottom stripes are red. Since the 18th century, Austria has been identified with this tricolor pattern, which is a well-known representation of the history and identity of the nation. The historical importance of red and white is that they stand for bravery and the nation's ongoing fight for freedom and independence.

Approach:

For drawing the Austrian flag in MATLAB:

• As a starting point for plotting, set up a figure.
• Specify the flag's measurements, normally 2:3 in height to breadth.
• Using the criteria for the Austrian flag, get the precise RGB values for the red and white colors.
• Use the rectangle function to represent the flag's red stripes by drawing the top and lower red rectangles.
• The white stripe of the flag is represented by the central white rectangle that should be drawn.
• Use the command ' set (gca,' visible,'' off')' to hide the axes and depict the flag.

Implementation:

Output:

• Creating a new figure to design the flag is the first step in setting up the figure.
• Setting the parameters: Set the flag's dimensions to match those of the Austrian flag, which normally has a height-to-width ratio of 2:3.
• The RGB values for the red and white colors should be defined by the specific tones used in the Austrian flag.
• Drawing the red rectangle: To create the red rectangle that represents the top and bottom stripes of the Austrian flag, use the rectangle function.
• Drawing the white rectangle: Similarly, use the ' rectangle' function to create a rectangle for the middle stripe of the flag with the desired size and is colored white.

• Make a 300x400x3-dimensional (3-dimensional) zero matrix. With 300 pixels for rows, 400 pixels for columns, and 3 pixels to represent the RGB color channels, this displays the image.
• Spray bottle green across the entire picture. To verify that the values are inside the range [0, 1], set the Red component to 0, the Green component to 102, and the Blue component to 51, all divided by 255.
• Draw the circle in the middle of the image using the equation for a circle. ((x - h)2 + (y - k)2 = r2, where (h, k) are the coordinates of the circle's center, (x, y) are the coordinates on the image plane and r radius of the circle.
• Determine the correct values for the circle's radius and center coordinates based on the image's dimensions.

Check whether each pixel is contained within the circle using nested loops. If it does, make that pixel's color bright red.

Implementation:

Output:

Explanation:

Making the Image Matrix: A 3D zero matrix with dimensions 300x400x3 is made to represent the image. In this case, 300 denotes the number of pixels for the rows, 400 denotes the number of pixels for the columns, and 3 denotes the RGB format's three color channels.

Background Color: By providing the right values for the red, green, and blue color components, a bottle green background is added to the image matrix.

Setting Circle Parameters: The radius and center coordinates of the circle are set. The radius is 50, and the center is at (200, 150).

The circle is drawn by iterating through each pixel in the image using nested loops. If the pixel is contained within, the red, green, and blue components are adjusted to make the area inside the circle a vivid red color.

## Drawing Japanese Flag

The steps to draw the Japanese flag in MATLAB are as follows:

Make an image matrix: Produce a 300x400x3-dimensional (3-dimensional) matrix of zeros to represent the image.

• Set the red, green, and blue component values to 1 to create a white background for the entire image.
• Establish the parameters for the circle that will be drawn in the middle. This provides the circle's radius and its center coordinates.

Draw the Circle: Iterate through each pixel in the image using nested loops. Using the circle equation, determine whether the pixel is inside the circle's perimeter, and if it is, change its color to a bright red one.

Implementation:

Output:

Defining Circle Parameters: The circle's radius is 50, and its center coordinates are (200, 150).

Drawing the Circle: The code iterates through every pixel in the 300x400 picture matrix using nested loops. The code sets the RGB values to generate a brilliant red circle by determining whether the pixel is within the limits of the circle using the equation of a circle.

Displaying the Flag: The imshow() function displays the final image matrix, which now includes the red circle. The exhibited image has the addition of the title "Flag of Japan" for clarification.

## Drawing the Sweden Flag using Matlab

A colored image is represented as a 3D matrix in MATLAB. The first dimension of an image corresponds to its rows, the second to its columns, and the third to the color information included in each pixel. The third dimension for the RGB color format specifically consists of three numbers that, when combined, represent the relative intensities of the Red, Green, and Blue hues.

### Approach:

Each element in this 3D matrix can be recognized by its row, column, and three color values. The construction, alteration, and viewing of diverse colored images are made possible by manipulating these parameters. The image's dimensions dictate the matrix's size, with the scale and resolution of the image being reflected in the number of rows and columns.

Making a Zero Matrix: Make a 300x600x3-dimensional (3-dimensional) zero matrix. In this case, 300 stands for the number of pixels in the rows, 600 for the number of pixels in the columns, and 3 for the RGB color coding scheme.

Painting the Background Blue: Change the image's values to blue to represent the color. Blue is denoted by the values (0, 0, 255), where the first two values signify the lack of red and green, and the last value indicates full-intensity blue in the RGB format.

Making the Horizontal Yellow Bar: Draw a yellow line across the picture. Yellow's RGB representation is (255, 255, 0), which indicates that red, green, and blue are all present in their full strength.

Making the Vertical Yellow Bar: Draw a vertical yellow bar on the image using yellow's RGB color code.

Implementation:

Output:

## Drawing Seychelles Flag.

A colored image can be modeled as a 3D matrix in MATLAB. The first dimension of an image corresponds to its rows, the second to its columns, and the third to the color information included in each pixel. The third dimension for the RGB color format specifically consists of three numbers that, when combined, represent the relative intensities of the Red, Green, and Blue hues.

• Each element in this 3D matrix can be recognized by its row, column, and three color values. The construction, alteration, and viewing of diverse colored images are made possible by manipulating these parameters.
• The image's dimensions dictate the matrix's size, with the scale and resolution of the image being reflected in the number of rows and columns.

Making the Matrix: Make a 300x600x3-dimensional (3-dimensional) zeros matrix. In this case, 300 stands for the number of pixels in the rows, 600 for the number of pixels in the columns, and 3 for the RGB color coding.

• To color the image, access each matrix pixel and modify its RGB value to correspond to the color blue. The RGB color code for blue in the Seychelles flag is (0, 63, 135). The entire image will be tinted blue, becoming the backdrop
Set the slope of the yellow area, which forms a 57-degree angle with the X-axis, to 1.55 degrees.
• Check each pixel in the image iteratively to see if its slope toward the origin is less than or equal to 1.55.
• Change the RGB value of the pixel to yellow if the requirement is met. The Seychelles flag's yellow color is represented by the RGB values (252, 216, 86).

Implementation:

Output:

It sets the background to blue, draws diagonal stripes in yellow and white, and then generates a 3D matrix of zeros to represent the image. The Seychelles flag is displayed using the 'imshow' function, and the plot is given a title using the 'title' function.

## Drawing Switzerland flag

Approach:

Create a 3D matrix with the initial values of 30x50x3. Each pixel's RGB values are represented by the three dimensions, where 30 specifies the number of rows, 50 denotes the number of columns, and 3 identifies the red, green, and blue color channels.

• Where the RGB values for red are (255, 0, 0), make the entire image red. This action creates the Switzerland flag's background.
• The flag should have a horizontal white bar. Use the RGB value of (255, 255, 255) for white and place it where it belongs in the image.
• Add a vertical white bar to complete the Switzerland flag's design.

Explanation:

The process entails building a matrix depicting the flag with specific dimensions corresponding to the flag's size. The matrix appropriately depicts the colors of the Swiss flag by allocating the correct RGB values. The distinctive cross emblem, a distinguishing feature of the Swiss national flag, is created by the insertion of the white bars, both horizontally and vertically. The 3D matrix representation accurately depicts the flag's design and layout by carefully controlling and modifying individual pixel colors.

Implementation:

Output:

This line transforms the array into an unsigned 8-bit integer type, I = uint8(I);. The 'uint8' class in MATLAB limits each color channel's value range to be between 0 and 255, which is the typical range for pixel values in images.

• I(:,:,1) = 255; creates a red image by setting all values in the first dimension (corresponding to the red color channel) to 255.
• I(5:25, 22:28, 1:3) = 255; By changing the values of the pixels in the specified range to 255
• for all three color channels, this line produces a white horizontal bar. The columns are represented by the range 22:28 and the rows by the range 5:25. Thus, the crimson backdrop is divided into a white bar by this line.

## Drawing Kuwait Flag

Approach:

A colorful image may be represented in MATLAB as a three-dimensional matrix, where the first dimension corresponds to the rows, the second to the columns, and the third to the color of the corresponding pixel. Red, Green, and Blue each have three values in the third dimension for the RGB color system. The intended size of the image determines the values of the rows and columns.

• A 3D matrix of the flag's design would be made to draw the Kuwaiti flag. The top and bottom stripes of Kuwait's flag are green, while the middle stripe is white, with three horizontal stripes in between. In addition, a black trapezoid on the flag's left side is intended to represent the Arabic language.
• To generate the Kuwaiti flag in MATLAB, you would create the matrix accordingly, defining the required ranges for the colors and shapes.
• Setting the values of particular ranges of rows and columns to the corresponding RGB values for the green, white, and black hues would do this.
• After building the matrix, you would use the imshow function to display the image in a figure window.

### Explanation:

• Make a 300X500X3 matrix with three orders. Three indicates the RGB color coding, 300 indicates the number of pixels for rows, and 500 indicates the number of columns.
• Due to all of the pixels having the same color code (0, 0, 0), the image is initially absolutely dark.
• The horizontal bar between columns 101 and 500 should be painted green. The Kuwaiti flag's green color code is (0, 122, 61).
• The horizontal bar between columns 101 and 500 and between rows 101 and 200 should be painted white. White has a color value of (255, 255, 255).
• The horizontal bar between columns 101 and 500 and rows 201 and 300 should be painted red. Red's color designation

Implementation:

Output:

I = uint8(zeros(300, 500, 3)); initializes a 3D matrix I with dimensions 300x500x3, and all entries are set to zero.

Green Horizontal Bar: The following set of lines sets the values of the pixels in the (1:100, 101:500) range to represent the green hue found in the Kuwaiti flag.

White Bar: The lines after the white horizontal bar define the values of the pixels in the (101:200, 101:500) range as the white color of the flag.

Red Bar: To depict the red hue of the flag, the lines then set the values of the pixels in the range (201:300, 101:500).

Next TopicMATLAB Indexing