Computer Vision Lab 02: Intensity Transformations Lab Objectives: In this lab, you will: Histogram of image. Histogram Equalization. 1.1 Image Negative: In digital image processing, the negative of an image is an operation that involves inverting the colors of the image. It is a simple image processing operation that can be used to enhance the visibility of certain features in an image or to produce interesting visual effects. The process of obtaining the negative of an image involves subtracting the pixel values of the original image from the maximum pixel value that can be represented by the image format. For example, if the image format uses 8 bits per pixel, the maximum pixel value is 255. To obtain the negative of an image, we subtract each pixel value from 255. The resulting image will have colors that are the complement of the original colors. For example, black pixels in the original image will become white pixels in the negative image, and vice versa. Similarly, red pixels in the original image will become cyan pixels in the negative image, green pixels will become magenta, and blue pixels will become yellow. The negative of an image can be useful in a variety of applications, including medical imaging, microscopy, and computer vision. For example, in medical imaging, the negative of an X-ray image can be used to enhance the visibility of certain features, such as bone fractures. In microscopy, the negative of an image can be used to highlight the shape and structure of cells or other microscopic objects. In computer vision, the negative of an image can be used as a preprocessing step for edge detection or other image analysis tasks. Negative of image equation. Copyright © [2023] [Hamid Ashfaq]. All rights reserved. Computer Vision Lab 02: Intensity Transformations 1.2 Log Transformation: In digital image processing, log transformation is a common technique used to enhance the contrast of an image. The transformation is achieved by taking the logarithm of each pixel value in the image. The formula for log transformation is as follows: s = c * log(1 + r) where s is the output pixel value, r is the input pixel value, c is a constant scaling factor, and log is the natural logarithm. The log transformation has the effect of compressing the dynamic range of the image. In other words, it enhances the contrast of the image by increasing the brightness of dark regions and decreasing the brightness of bright regions. This can be particularly Copyright © [2023] [Hamid Ashfaq]. All rights reserved. Computer Vision Lab 02: Intensity Transformations useful in images that have a large range of brightness values, such as medical images or satellite images. One of the advantages of log transformation is that it is a nonlinear transformation, meaning that it can enhance contrast in a way that is not possible with linear transformations such as histogram equalization. However, log transformation should be used with caution, as it can introduce artifacts in some images and can also cause loss of information in very dark or very bright regions. Log transformation is a common technique used in a variety of image processing applications, including medical imaging, remote sensing, and computer vision. It can be implemented using standard image processing software or programming languages such as MATLAB or Python. The above picture shows the importance of histogram in Image Processing domain. 1.3 Histogram of Image? Copyright © [2023] [Hamid Ashfaq]. All rights reserved. Computer Vision Lab 02: Intensity Transformations In digital image processing, a histogram is a graphical representation of the distribution of pixel intensity values in an image. The histogram of an image can provide useful information about the contrast and brightness of the image, as well as the overall distribution of pixel intensities. A histogram is created by counting the number of pixels in an image that have a specific intensity value, and then plotting these values as a bar graph. The horizontal axis of the histogram represents the range of possible intensity values, while the vertical axis represents the number of pixels in the image that have each intensity value. For example, in a grayscale image with 256 possible intensity values (ranging from 0 to 255), the histogram would have 256 bins, one for each possible intensity value. The height of each bar in the histogram would represent the number of pixels in the image that have that intensity value. The shape of the histogram can provide valuable insights into the properties of the image. A histogram with a peak at the centre of the intensity range indicates an image with average brightness, while a histogram with a peak at either end of the intensity range indicates an image with low or high contrast. A histogram with multiple peaks may indicate an image with multiple dominant colours or textures. Histograms can be used for a variety of image processing tasks, including contrast stretching, histogram equalization, and thresholding. These techniques can be used to enhance the contrast and visibility of certain features in an image, or to segment an image into regions based on intensity values. Histograms can also be used to compare the properties of different images or to identify anomalies in an image dataset. Copyright © [2023] [Hamid Ashfaq]. All rights reserved. Computer Vision Lab 02: Intensity Transformations 1.4 Histogram Equalization of Image Histogram equalization is a technique used in digital image processing to enhance the contrast and brightness of an image. The technique works by adjusting the image's histogram so that the distribution of pixel intensities is more uniform across the entire range of possible intensity values. The process of histogram equalization involves the following steps: Compute the image histogram: Count the number of pixels in the image that have each possible intensity value. Compute the cumulative distribution function (CDF) of the histogram: Calculate the cumulative sum of the histogram values, normalized by the total number of pixels in the image. Compute the desired intensity transformation function: Apply a suitable transformation function to the CDF to obtain a new intensity mapping that will redistribute the pixel intensities in the image. Apply the transformation function to the image: Map each pixel in the image to its new intensity value according to the desired transformation function. The result of histogram equalization is an image with improved contrast and brightness, where the full range of possible intensity values is utilized more evenly. The technique is particularly effective for images with low contrast or with a narrow range of intensity values, such as images captured under poor lighting conditions. Histogram equalization can be implemented using standard image processing software or programming languages such as MATLAB or Python. However, it should be used with caution, as it can sometimes result in artifacts or distortions in the image, particularly in regions with very high or very low pixel intensities. Variations of histogram equalization, Copyright © [2023] [Hamid Ashfaq]. All rights reserved. Computer Vision Lab 02: Intensity Transformations such as adaptive histogram equalization, may be used to overcome some of these limitations. Copyright © [2023] [Hamid Ashfaq]. All rights reserved. Computer Vision Lab 02: Intensity Transformations Lab Task: Note: Built in Libraries are not allowed to use. Create your own code. Marks will be deducted. If used libraries except basic libraries to read, write and display functions. Use of at least one grayscale image and one coloured image RGB in each question. Questions: 1. Create Negative of image in Python. Use of grayscale image and one coloured image RGB. 2. Write a code for log transformation in python. Copyright © [2023] [Hamid Ashfaq]. All rights reserved. Computer Vision Lab 02: Intensity Transformations 3. Write a code to show histogram of image. 4. Enhance the image using histogram equalization. Copyright © [2023] [Hamid Ashfaq]. All rights reserved.