
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Intensity Transformation Operations on Images in MATLAB
Introduction to Intensity Transformation in MATLAB
In MATLAB, the intensity transformation operation on images is one of the most fundamental image processing technique. It is an image processing operation in which the results depend on the intensity of an image. In MATLAB, the intensity transformation operations on images are performed to correct, enhance, or manipulate the intensity of image pixels. We have various built-in MATLAB functions to perform intensity transformation operations on images.
In this article, we will discuss some commonly used intensity transformation operations and will see how they can be implemented using MATLAB programming.
Intensity Transformation Operations in MATLAB
In this article, we will cover all these intensity transformation operations in MATLAB
Image Negatives
Log Transformation
Power Law Transformation
Brightness Adjustment
Image Negatives in MATLAB
In MATLAB, we use the following intensity transformation operation to find the negative of an image:
Negative_image = 255 - input_image
Example
% MATLAB program to demonstrate image negative transformation % Insert a color input image using imread function input_image = imread('https://www.tutorialspoint.com/assets/questions/media/14 304-1687425269.jpg'); % Find the negative of the input image negative_image = 255 - input_image; % Display the original image and negative image subplot(1, 2, 1), imshow(input_image), title('Original Image') subplot(1, 2, 2), imshow(negative_image), title('Negative Image') % Save the negative image in jpg format imwrite(negative_image, 'negative_image.jpg');
Output
Explanation
In this MATLAB program, we input a color image by calling "imread('https://www.tutorialspoint.com/assets/questions/media/14304-1687425269.jpg');" function. This function stores the input image in the "input_image" variable. After that we compute the negative of the input image by subtracting each pixel intensity from 255. This is done by the formula "255 - input_image", then the result is stored in the "negative_image" variable.
After that, we call "subplot" and "imshow" functions to display the original image and negative image side by side. Finally, we call "imwrite" function to save the negative image as "negative_image.jpg".
Log Transformation of Image in MATLAB
In MATLAB, the log transformation operation is used replace all image pixel values present in the image with its logarithmic values to enhance the image. This intensity transformation operation expands the dark pixels of the image than its higher pixel values.
The following expression is used to perform the log transformation of an image in MATLAB:
log_transformation = c * log(1 + input_image)
Example
% MATLAB program to demonstrate log transformation of image % Input an image input_image = imread('https://www.tutorialspoint.com/assets/questions/media/14 304-1687425269.jpg'); % Convert the image to double datatype for calculations input_image = im2double(input_image); % Constant to determine the nature of the log curve c = 1; % Perform the log transformation log_transformed = c * log(1 + input_image); % Display the original image and log-transformed image subplot(1, 2, 1), imshow(input_image), title('Original Image') subplot(1, 2, 2), imshow(log_transformed), title('Log-Transformed Image') % Save the log-transformed image imwrite(log_transformed, 'log_transformed_image.jpg');
Output
Explanation
In this MATLAB program, we call the function "imread" to input an image and store it into the "input_image" variable. Then, we call the function "im2double" to change the image datatype to double for allowing fractional values in calculation. After that define a constant "c" with a value "1" to determine the nature of the log curve. Then, perform the log transformation of the image by using the formula "log_transformed = c * log(1 + input_image)". Then, we call the functions "subplot" and "imshow" to display the original and log-transformed images side by side. Finally, we call the function "imwrite" to save the log-transformed image with a name "log_transformed_image.jpg".
Power Law Transformation of Image in MATLAB
Power law transformation operation is performed on an image to enhance it for different types of display devices. This image transformation is required because different display devices have different gamma values.
The following formula is used to perform the power law transformation operation in MATLAB:
power_law_transformed_image = input_image .^ gamma
Example
% MATLAB program to demonstrate power law transformation of image % Input an image input_image = imread('https://www.tutorialspoint.com/assets/questions/media/14 304-1687425269.jpg'); % Convert the image to double datatype for calculations input_image = im2double(input_image); % Set a desired gamma value for the power law transformation gamma = 0.4; % Perform the power law transformation of image power_law_image = input_image .^ gamma; % Display the original and power law transformed images subplot(1, 2, 1), imshow(input_image), title('Original Image') subplot(1, 2, 2), imshow(power_law_image), title('Power Law Transformed Image') % Save the power law transformed image imwrite(power_law_image, 'power_law_transformed_image.jpg');
Output
Explanation
In this MATLAB program, we call the function "imread" to input an image and store it into the "input_image" variable. Then, we call the function "im2double" to change the image datatype to double for allowing fractional values in calculation. After that set a desired value of gamma as per the requirements. If the value of gamma is greater than 1, then it enhances the brighter regions of the image, and if the gamma value is less than 1, then it enhances the darker regions of the image.
Then, we perform the power law transformation of the image by using the formula "power_law_image = input_image .^ gamma". Then, we call the functions "subplot" and "imshow" to display the original and power law transformed images side by side. Finally, we call the function "imwrite" to save the power law transformed image with a name "power_law_transformed_image.jpg".
Brightness Adjustment of an Image in MATLAB
Brightness adjustment is used to transform the intensity of light in an image.
In MATLAB, we can use the following formula to adjust the brightness in an image:
bright_image = input_image + bright_value
Example
% MATLAB program to demonstrate brightness adjustment of image % Input an image input_image = imread('https://www.tutorialspoint.com/assets/questions/media/14304-1687425269.jpg'); % Set a desired brightness value for the brightness transformation bright_value = 60; % Perform the brightness adjustment of the image bright_image = input_image + bright_value; % Display the original and brightness adjusted images subplot(1, 2, 1), imshow(input_image), title('Original Image') subplot(1, 2, 2), imshow(bright_image), title('Brightness Adjusted Image') % Save the brightness adjusted image imwrite(bright_image, 'brightness_adjusted_image.jpg');
Output
Explanation
In this MATLAB program, we call the function "imread" to input an image and store it into the "input_image" variable. Then, we set a desired value of brightness as per the requirements. After that we perform the brightness transformation of the image by using the formula "bright_image = input_image + bright_value". Then, we call the functions "subplot" and "imshow" to display the original and brightness transformed images side by side. Finally, we call the function "imwrite" to save the brightness adjusted image with a name "'brightness_adjusted_image.jpg".
Conclusion
Hence, this is all about intensity transformation operations on images in MATLAB. We can perform various intensity transformation operations on images to enhance them. In the above sections of this article, we have described four commonly used intensity transformation operations with the help of example MATLAB programs and their outputs.