Javatpoint Logo
Javatpoint Logo

Image Processing in MATLAB | Fundamental Operations

In MATLAB, image processing involves modifying digital images to improve, examine, and extract usable information. MATLAB offers a robust framework for carrying out different image-processing tasks.

Determining image attributes, modifying image features, and enhancing image quality using Matlab are image processing and analysis fundamentals.

Prerequisites:

  • Install Matlab on your computer.
  • Basic knowledge of Matlab is required.
  • Using MATLAB for image processing, you can carry out the following basic operations:

Reading an image:

An image from a file can be read using the imread() function. It gives back a matrix with each cell denoting a pixel value.

Don't forget to substitute the correct path to your image file for "image.jpg." You must specify the right path if the image is not in the same directory as your MATLAB script or workspace.

Example:

Can specify the path to the image you want to read inside the single quotes.

Note: The output typically seen in the Command Window is suppressed by adding a semicolon (;) at the end of a MATLAB command. This might be extremely helpful when you're carrying out several tasks and want the outcomes to be clear of your workstation and slow down your workflow.

Displaying Images:

A key component of image processing and analysis is image display. This frequently requires the imshow tool from MATLAB. Here is a more detailed explanation of how to display photographs and some extra choices you can use.

Basic Image Display:

Customizing Display:

Can alter the imshow function's functionality using a variety of optional arguments:

Set the image's initial magnification level using the 'InitialMagnification' option.

DisplayRange: Define the display's intensity range.

Colormap: Set the Colormap for indexed pictures with Colormap.

Title: Show the figure's title.

Border: Indicate whether or not to surround the image with a border.

Parent: Choose a certain axis item to display.

Multiple Image Display:

Displaying Images in Different Colorspaces:

Using the imshow function, you can display images in different colorpaces. If you want to use a different colormap to display a grayscale image, for instance:

Binary image display:

This shows the binary BW image. It shows pixels with 0 (zero) as black and 1 (white) as pixels.

  • While imshow is a fantastic tool for rapid picture visualization, more complex image analysis frequently calls for more features and tools in the MATLAB picture Processing Toolbox.
  • Additionally, if you don't want to display the statistics for pixel values, think about using semicolons to suppress the output of imshow calls.

Writing Pictures:

The imwrite function in MATLAB lets you save images to disk. The image data, file type, filename, and optional parameters must be supplied.

Alternatively, we could write it as write (f, 'nature,' 'jpg'). As mentioned, the commands write image f to a filename nature with the extension jpg.

The imwrite function supports various file formats and settings, so keep that in mind. For further details on supported formats and available choices, consult the official MATLAB documentation.

Image filtering:

Using various filters, image filtering is a fundamental approach in image processing to improve or modify images. To create various effects, matrices called filters are convolved with an image's pixel values.

  • Edge detection, noise reduction, sharpening, and blurring are typical uses for picture filtering.
  • The filter function in MATLAB is used to carry out image-filtering tasks.

An in-depth look at MATLAB's image filtering is provided here:

Blurring (Smoothing) Filter: Images with less noise have a smoother appearance thanks to blurring filters. The average filter and the Gaussian filter are both frequently used blurring filters.

Histogram equalization:

The histeq function is used to enhance the contrast of an image by redistributing its intensity levels.

Connected Components Analyzing:

In a binary image, connected components are labeled using the bwlabel function. It aids in differentiating items.

Thresholding Methodologies:

Like Otsu's technique, MATLAB offers a variety of thresholding functions for automatic threshold selection.

These are only a few basic tasks that MATLAB can carry out while processing images. You can use various MATLAB picture Processing Toolbox functions to help with picture modification tasks.

Implementation:

Output:

Image Processing in MATLAB | Fundamental Operations
  • The actual image loads and appears on the screen.
  • The image is exhibited after being grayscaled.
  • The grayscale image is processed using a Gaussian filter before being shown.
  • The grayscale image undergoes histogram equalization and is then shown. The grayscale image is subjected to canny edge detection and shown.
  • The grayscale image is subjected to binary thresholding to create a binary image, which is presented.
  • A file is created and contains the modified binary image. Image Loading: The program begins with the imread function to load the "download.png" image.

Displaying the Original Image: The imshow function displays the original image within a subplot.

Grayscale conversion: The rgb2gray function converts the loaded color image to grayscale, after which the grayscale image is displayed.

How to Apply a Gaussian Filter: The Gauss function was used to apply a Gaussian filter on the grayscale image. This contributes to noise reduction and image smoothing. It shows the filtered image.

Histogram Equalization: The histeq function applies histogram equalization to the grayscale image. Shifting the intensity levels of the image improves contrast. It shows the equalized image.

  • Edge function with the 'canny' parameter is used to apply the Canny edge detection method to the grayscale image.
  • This draws attention to the image's edges. Displayed is the edge-detected image.

Binary Thresholding: A binary image can be created using the binarize function to apply a threshold to the grayscale image. The graythresh function is used to calculate the threshold value. It shows the binary image.

Display and Subplots: The subplot function allows you to group several images into a single figure window. In a subplot, each processed image is shown.

  • To set a title for the complete figure that describes the function of the shown images, use the subtitle function.

The application demonstrates a series of fundamental image processing operations, including loading, grayscale conversion, filtering, histogram equalization, edge detection, and binary thresholding.

  • This is a condensed illustration of how these operations work. More complicated algorithms and techniques could be applied for advanced image processing tasks in real-world applications.

Benefits and Limitations:

Usefulness: Thanks to its interactive development tools and straightforward syntax, MATLAB offers a user-friendly environment for image processing applications.

Rich Toolbox: The Image Processing Toolbox provided by MATLAB is a comprehensive collection of tools, algorithms, and routines for diverse image processing activities.

Visualization: You may show and analyze images using MATLAB's rich visualization features, which improve understanding of the findings.

Community Support: Since there is a sizable user base for MATLAB, it is easy to access tutorials, documentation, and support online.

Integration: You may combine image processing with tasks like data analysis or machine learning by combining MATLAB with other toolboxes and libraries.

Algorithm Development: MATLAB makes it easier to build algorithms by giving users a platform to test various methods and evaluate their outcomes.

Limitations:

Performance: Although MATLAB can handle small to medium-sized image processing workloads, lower-level languages like C++ or CUDA for high-performance processing of huge images or real-time applications

may be more effective.

Memory Usage: MATLAB can use a lot of memory for complex picture processing, which could be a drawback for systems with constrained resources.

Speed: MATLAB may be slower than compiled languages for complex computations due to how it is interpreted.

Commercial License: Since MATLAB is a for-profit product, getting a license could be a barrier for some users.

Limited Flexibility: Some sophisticated or customized image processing methods may need more control and tailoring than MATLAB's toolbox can provide.

Not GPU Optimized: Although MATLAB includes some GPU support, there may be some tasks for which it needs to be GPU optimized.

Vendor Lock-in: Creating sophisticated image processing systems only in MATLAB may result in vendor lock-in, making it difficult to switch to other platforms.

  • The Image Processing Toolkit in MATLAB is an effective tool for various image processing activities, particularly for study, prototyping, and smaller-scale jobs.






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




news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news