MATLAB 中图像的强度变换操作
MATLAB 中强度变换简介
在 MATLAB 中,图像的强度变换操作是最基本的图像处理技术之一。它是一种图像处理操作,其结果取决于图像的强度。在 MATLAB 中,图像的强度变换操作用于校正、增强或操作图像像素的强度。我们有各种内置的 MATLAB 函数来执行图像的强度变换操作。
在本文中,我们将讨论一些常用的强度变换操作,并了解如何使用 MATLAB 编程实现它们。
MATLAB 中的强度变换操作
在本文中,我们将介绍 MATLAB 中所有这些强度变换操作
图像反转
对数变换
幂律变换
亮度调整
Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.
MATLAB 中的图像反转
在 MATLAB 中,我们使用以下强度变换操作来查找图像的反转图像
Negative_image = 255 - input_image
示例
% MATLAB program to demonstrate image negative transformation % Insert a color input image using imread function input_image = imread('https://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');
输出
解释
在这个 MATLAB 程序中,我们通过调用 "imread('https://tutorialspoint.com/assets/questions/media/14304-1687425269.jpg');" 函数输入彩色图像。此函数将输入图像存储在“input_image”变量中。之后,我们通过从 255 中减去每个像素强度来计算输入图像的反转图像。这是通过公式“255 - input_image”完成的,然后结果存储在“negative_image”变量中。
之后,我们调用“subplot”和“imshow”函数并排显示原始图像和反转图像。最后,我们调用“imwrite”函数将反转图像保存为“negative_image.jpg”。
MATLAB 中的图像对数变换
在 MATLAB 中,对数变换操作用于将图像中存在的所有图像像素值替换为其对数值以增强图像。此强度变换操作扩展了图像的暗像素而不是其较高的像素值。
以下表达式用于在 MATLAB 中执行图像的对数变换
log_transformation = c * log(1 + input_image)
示例
% MATLAB program to demonstrate log transformation of image % Input an image input_image = imread('https://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');
输出
解释
在这个 MATLAB 程序中,我们调用函数“imread”来输入图像并将其存储到“input_image”变量中。然后,我们调用函数“im2double”将图像数据类型更改为 double 以允许在计算中使用小数。之后定义一个值为“1”的常数“c”来确定对数曲线的性质。然后,使用公式“log_transformed = c * log(1 + input_image)”执行图像的对数变换。然后,我们调用函数“subplot”和“imshow”并排显示原始图像和对数变换图像。最后,我们调用函数“imwrite”以名称“log_transformed_image.jpg”保存对数变换图像。
MATLAB 中的图像幂律变换
对图像执行幂律变换操作以增强不同类型的显示设备。需要此图像变换是因为不同的显示设备具有不同的伽马值。
以下公式用于在 MATLAB 中执行幂律变换操作
power_law_transformed_image = input_image .^ gamma
示例
% MATLAB program to demonstrate power law transformation of image % Input an image input_image = imread('https://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');
输出
解释
在这个 MATLAB 程序中,我们调用函数“imread”来输入图像并将其存储到“input_image”变量中。然后,我们调用函数“im2double”将图像数据类型更改为 double 以允许在计算中使用小数。之后根据需要设置所需的伽马值。如果伽马值大于 1,则它会增强图像的亮度区域,如果伽马值小于 1,则它会增强图像的暗色区域。
然后,我们使用公式“power_law_image = input_image .^ gamma”执行图像的幂律变换。然后,我们调用函数“subplot”和“imshow”并排显示原始图像和幂律变换图像。最后,我们调用函数“imwrite”以名称“power_law_transformed_image.jpg”保存幂律变换图像。
MATLAB 中的图像亮度调整
亮度调整用于变换图像中的光强度。
在 MATLAB 中,我们可以使用以下公式调整图像的亮度
bright_image = input_image + bright_value
示例
% MATLAB program to demonstrate brightness adjustment of image % Input an image input_image = imread('https://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');
输出
解释
在这个 MATLAB 程序中,我们调用函数“imread”来输入图像并将其存储到“input_image”变量中。然后,我们根据需要设置所需的亮度值。之后,我们使用公式“bright_image = input_image + bright_value”执行图像的亮度变换。然后,我们调用函数“subplot”和“imshow”并排显示原始图像和亮度变换图像。最后,我们调用函数“imwrite”以名称“'brightness_adjusted_image.jpg”保存亮度调整后的图像。
结论
因此,这就是关于 MATLAB 中图像强度变换操作的全部内容。我们可以对图像执行各种强度变换操作以增强它们。在本文的上述部分中,我们借助示例 MATLAB 程序及其输出描述了四种常用的强度变换操作。