Javatpoint Logo
Javatpoint Logo

Matlab Program to Rotate an Image 180 Degrees Clockwise Without Using Function

A two-dimensional function, f(x, y), can describe images. The value of f at any given pair of coordinates (x, y) is the intensity or gray level of the image at that particular position. We label an image as a digital image when x, y, and the intensity values of f are all discrete, finite quantities.

  • A digital image has a finite number of elements, each with a unique location and value.
  • Common names for these discrete components include picture elements, image elements, and plain old pixels.
  • The smallest component of an image is a pixel, and each pixel has a unique numerical value.

Without Using Function:

An image represents visual data and can be considered a mathematical function with the notation f(x, y). 'x' and 'y' in this illustration stand for the spatial coordinates of a two-dimensional plane. The intensity or gray level of the image at each given pair of coordinates (x, y) is represented by the value of this Function at that specific position. It controls how bright or dark a specific point in the image looks.

  • We classify an image as a digital image when the spatial coordinates "x" and "y," as well as the intensity values of the image function "f," are all discrete and finite.
  • In other words, digital images are those in which each component's intensity and location are known.

Implementation:

Output:

Matlab Program to Rotate an Image 180 Degrees Clockwise Without Using Function

Explanation:

Read the graphic: Using the imread Function, the code first reads the input picture 'orangefl.jpg.' It will be 180 degrees clockwise turned.

Get the Dimensions: Using the size function, the code extracts the dimensions of the input image. It returns the input image's number of rows, columns, and color channels (usually three for RGB images).

  • The variables rows, cols, and are used to hold the dimensions; the tilde character is used to discard the color channel data because it isn't required in this Function.

Produce an Empty Matrix: The zeros function produces an empty matrix with the name rotated image. The rotated image will be kept in this matrix. Its proportions match those of the input image.

Rotate the image: The code cycles through each pixel in the input image using nested for loops. To perform the 180-degree clockwise rotation, it swaps the coordinates (i, j) to (rows - I + 1, cols - j + 1) between the loops, assigning the pixel value from the original image to the matching spot in the rotated image.

Save the Rotated Image: Using the write Function, you can, if necessary, save the rotated image to a file with the name "rotated"

Approach:

Read the graphic: The imread Function reads an image with the filename "apple1.png" and saves the data in the variable a. The image is loaded from the specified file by this line.

Display the Original Image: Using the imshow Function, it displays the original image saved in the variable a. Additionally, it changes the display window's title to "Original Image."

Rotate the Image 180 Degrees Clockwise: The code generates a new image I by flipping the rows and columns of the original image stored to rotate the image 180 degrees clockwise. The image is efficiently flipped horizontally and vertically by indexing with notation.

Display the Rotated Image: Using the imshow Function, the rotated image i is displayed in a new figure. It displays an image rotated 180 degrees in the clockwise direction. The title of the display window can be added if necessary, even though it is not set in the code.

Implementation:

Output:

Matlab Program to Rotate an Image 180 Degrees Clockwise Without Using Function

Flips the image upside down, then from left to right, rotating it 180 degrees clockwise and displaying the result.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA