Image Enhancement with MATLAB 

 December 5, 2019

By  MATLAB Helper


Image enhancement is the process of improving the quality of an image by manipulating the stored image before processing. It accentuates and sharpens image features such as edges, contrast, boundaries to make a graphic display more suitable for display and analysis. Some of the routines used to enhance the images are:

  1. Morphological operators
  2. Wiener filter.
  3. Contrast limited adaptive histogram equalization (CLAHE).
  4. Decorrelation stretch.
  5. Linear contrast adjustment.
  6. Median filtering.
  7. Unsharp mask filtering.
  8. Histogram Equalization.

Image enhancement algorithms are commonly applied to remotely sensed data to improve the appearance of an image and a new enhanced image is produced. The enhanced image is generally easier to interpret than the original image.

This blog will demonstrate few methods of image enhancement and the applications of image enhancement in the medical field.  This application is very useful for anyone who is working on medical images.

Now let’s have an understanding of each method and how they can be applied in the medical field.

1. Analyzing image using Morphological operations.

Morphology is a set of operations that process images based on shapes. Each pixel in the image is adjusted based on the value of other pixels in its neighborhood. Morphological operations can also be applied to grey-scale images such that their light transfer functions are unknown and therefore their absolute pixel values are of no or minor interest.

Structuring elements play a very important role in morphological operations. Structuring elements are small sets in matrix form or a sub-image used to interact with the image to be probed. The precise details can be obtained by choosing a suitable structuring element. Structuring elements in morphological image processing are the same as the convolution masks in linear image filtering.

The fundamental morphological operations are Dilation and Erosion.

  1. The dilation operation makes an object grow by size. The extent to which it grows depends on the nature and shape of the structuring element. The value of the output pixel is the maximum value of all pixels in the neighborhood. In a binary image, a pixel is set to 1 if any of the neighboring pixels have the value 1.

  2. The erosion is the operation of a complement of dilation operation in context with the operation effect. That is erosion operation causes an object to lose its size. The value of the output pixel is the minimum value of all pixels in the neighborhood. In a binary image, a pixel is set to 0 if any of the neighboring pixels have the value 0.

The functions in MATLAB that perform common morphological operations are imopen, imclose, bwskel, bwperim, imdilate, imerode, etc.

Morphological operations are used to analyze the objects, such as finding the number of coins on a surface, finding the area of a coin, and you can compute statistics for all objects in the image.

Below one is the image of the circles where the background illumination is brighter in the center of the image than at the bottom. 

image 20191014 093224 | Image Enhancement with MATLAB | MATLAB Helper ®

Preprocess the image to make the background illumination more uniform. Create a binary version of the processed image so you can use toolbox functions for analysis. 

image 20191014 095712 | Image Enhancement with MATLAB | MATLAB Helper ®

Now that you have created a binary version of the original image you can perform analysis of objects in the image.

Likewise, Morphological operations are used in many ways, To list a few they are used in hole filling, boundary extraction of objects, Thinning and thickening and so on. 

2. Deblurring image using wiener filter

Blurred image can be generated by convolving point spread function with original image. The point spread function (PSF) describes the response of an imaging system to a point source or point object. The degree of spreading (blurring) of the point object is a measure for the quality of an imaging system. fspecial function is used to create the point spread function by specifying linear motion. 

image 20191014 114229 | Image Enhancement with MATLAB | MATLAB Helper ®

The most important technique for removal of blur in images due to linear motion or unfocused optics is the Wiener filter. Wiener deconvolution of blurred image with point spread function gives the original image. The Wiener filtering is a linear estimation of the original image. Wiener filtering is optimal in terms of the mean square error. In other words, it minimizes the overall mean square error in the process of inverse filtering and noise smoothing.

deconvwnr deconvolves the blurred image and point spread function using the Wiener filter algorithm. The algorithm is optimal in a sense of least mean square error between the estimated and the true images.

image 20191014 120000 | Image Enhancement with MATLAB | MATLAB Helper ®

3. Contrast-limited adaptive histogram equalization

Adaptive histogram equalization is a computer image processing technique used to improve contrast in images. Unlike histogram equalization, adaptive method computes several histogram, each corresponding to a distinct section of the image. Adaptive histogram equalization has a tendency to over amplify noise in relatively homogeneous regions of an image.

In order to prevent this limitation, Contrast limited adaptive histogram equalization technique will be used. Contrast limited adaptive histogram equalization (CLAHE) is used for improve the visibility level of foggy image or video. In CLAHE, the contrast amplification in the vicinity of a given pixel value is given by the slope of the transformation function.

adapthisteq function enhances the contrast of the gray scale image by transforming the values using CLAHE. 

image 20191014 122935 | Image Enhancement with MATLAB | MATLAB Helper ®

4. Decorrelation stretching

Decorrelation stretching, a type of contrast stretching that results in the artificial enhancement in color of an image. The primary purpose of decorrelation stretch is visual enhancement. Decorrelation stretch is a linear, pixel-wise operation. The vector a containing the value of given pixel in each band of the input image A is transformed into the corresponding pixel B as follows:

b = T * (a - m) + m_target

T is the linear transformation matrix, m is the mean of each band and m_target is the desired output mean in each band. Order of a and b vectors is nbands x 1.

decorrstretch function is used to apply decorrelation stretching. The original color values of the image are mapped to a new set of color values with a wider range.

image 20191014 124954 | Image Enhancement with MATLAB | MATLAB Helper ®

Enhancement of medical images:

Graphical User Interface

Three panels are used to create the complete look of this application. Once the app starts running, the user first sees the Menu panel where the user must upload the input image on which enhancement is done by clicking the “Load Image“ button. After the image is loaded and can be viewed on the axis by the user by clicking the "Add Noise" button, the app will take you to the next panel, the Noisy panel where in noise is added to the input image. Proceed further by clicking the “Filter“ button used to filter the noise present and shown in the Comparison panel where further enhancement is done to the filtered images.The entire graphical user interface was created using MATLAB App Designer, and the webinar video below explains how to create it.

panels | Image Enhancement with MATLAB | MATLAB Helper ®

Graphical user interface was created using MATLAB App Designer


Once the application panel is ready, the next step is to write the code to determine the behavior for the components, the following image shows the overall workflow of the application design.

AMF: Adaptive median filter changes size of Sxy (the size of the neighborhood) during operation.

● Notation

  Zmin = minimum gray level value in Sxy

  Zmax = maximum gray level value in Sxy

  Zmed = median of gray levels in Sxy

  Zxy = gray level at coordinates (x, y)

  Smax = maximum allowed size of Sxy

● Algorithm

Level A: A1 = Zmed - Zmin

                 A2 = Zmed - Zmax

            if A1 > 0 AND A2 < 0, go to level B

else increase the window size

if window size < Smax, repeat level A

else output Zxy

Level B: B1 = Zxy - Zmin

     B2 = Zxy - Zmax

if B1 > 0 AND B2 < 0, output Zxy

else output Zmed

Flow chart of the adaptive median filter decision logic

dd | Image Enhancement with MATLAB | MATLAB Helper ®


Ultimately, This application will be very useful to Enhance a Medical Image in straightforward way. Image Enhancement are widely available, but their application are not well defined. This application allows end user to add Noise (Salt & Pepper, Gaussian, Speckle, Pepper). We explained few methods to enhance an Image by removing the noise. But, What is the best method to enhance an Image? Share your opinion in the Discussion section.

Did you find some helpful content from our video or article and now looking for its code, model, or application? You can purchase the specific Title, if available, and instantly get the download link.

Thank you for reading this blog. Do share this blog if you found it helpful. If you have any queries, post them in the comments or contact us by emailing your questions to [email protected]. Follow us on LinkedIn Facebook, and Subscribe to our YouTube Channel. If you find any bug or error on this or any other page on our website, please inform us & we will correct it.

If you are looking for free help, you can post your comment below & wait for any community member to respond, which is not guaranteed. You can book Expert Help, a paid service, and get assistance in your requirement. If your timeline allows, we recommend you book the Research Assistance plan. If you want to get trained in MATLAB or Simulink, you may join one of our training modules. 

If you are ready for the paid service, share your requirement with necessary attachments & inform us about any Service preference along with the timeline. Once evaluated, we will revert to you with more details and the next suggested step.

Education is our future. MATLAB is our feature. Happy MATLABing!

About the author 


MATLAB Helper ® is an organization providing programming expertise with assistance to students, professionals, researchers & and corporate.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Connect with MATLAB Helper ®

Follow: YouTube Channel, LinkedIn Company, Facebook Page, Instagram Page

Join Community of MATLAB Enthusiasts: Facebook Group, Telegram, LinkedIn Group

Use Website Chat or WhatsApp at +91-8104622179