matlab视觉设计图像去雾直方图均衡化代码
时间: 2024-01-07 08:23:20 浏览: 36
以下是使用Matlab进行图像去雾的直方图均衡化的代码示例:
```matlab
% 读取图像
image = imread('input_image.jpg');
% 将RGB图像转换为灰度图像
gray_image = rgb2gray(image);
% 对灰度图像进行直方图均衡化
equalized_image = histeq(gray_image);
% 显示原始图像和直方图均衡化后的图像
subplot(1, 2, 1);
imshow(gray_image);
title('原始图像');
subplot(1, 2, 2);
imshow(equalized_image);
title('直方图均衡化后的图像');
```
这段代码首先读取输入图像,然后将RGB图像转换为灰度图像。接下来,使用`histeq`函数对灰度图像进行直方图均衡化处理。最后,使用`imshow`函数显示原始图像和直方图均衡化后的图像。
请注意,你需要将代码中的`input_image.jpg`替换为你自己的图像文件路径。
相关问题
matlab视觉设计图像去雾代码
根据提供的引用内容,有两种方法可以实现matlab视觉设计图像去雾代码:
方法一:直方图均衡化+Retinex理论图像去雾
```matlab
% 读取图像
img = imread('input.jpg');
% 直方图均衡化
img_eq = histeq(img);
% Retinex理论图像去雾
R = img_eq(:,:,1);
G = img_eq(:,:,2);
B = img_eq(:,:,3);
R_retinex = log(1 + double(R));
G_retinex = log(1 + double(G));
B_retinex = log(1 + double(B));
img_retinex = cat(3, R_retinex, G_retinex, B_retinex);
img_retinex = uint8(img_retinex);
% 显示结果
subplot(1, 2, 1), imshow(img), title('原始图像');
subplot(1, 2, 2), imshow(img_retinex), title('去雾后图像');
```
方法二:暗通道图像去雾
```matlab
% 读取图像
img = imread('input.jpg');
% 计算暗通道图像
R = img(:,:,1);
G = img(:,:,2);
B = img(:,:,3);
dark_channel = min(min(R, G), B);
% 估计大气光
atmospheric_light = max(max(dark_channel));
% 估计透射率
omega = 0.95;
transmission = 1 - omega * dark_channel / atmospheric_light;
% 恢复原始图像
J = img;
J(:,:,1) = (img(:,:,1) - atmospheric_light) ./ transmission + atmospheric_light;
J(:,:,2) = (img(:,:,2) - atmospheric_light) ./ transmission + atmospheric_light;
J(:,:,3) = (img(:,:,3) - atmospheric_light) ./ transmission + atmospheric_light;
% 显示结果
subplot(1, 2, 1), imshow(img), title('原始图像');
subplot(1, 2, 2), imshow(J), title('去雾后图像');
```
图像直方图均衡化matlab代码
图像直方图均衡化是一种用来改善图像对比度的处理方法,它通过对图像的像素值进行变换,使得像素值的分布更加均匀,从而增强图像的细节和色彩。下面是一份基于Matlab的图像直方图均衡化代码示例:
1. 读取图像
```matlab
img = imread('image.jpg'); % 读取图像
```
2. 将图像转换为灰度图
```matlab
gray_img = rgb2gray(img); % 转换为灰度图
```
3. 计算图像的直方图
```matlab
histogram = imhist(gray_img); % 计算直方图
```
4. 计算直方图累积分布
```matlab
cumulative_histogram = cumsum(histogram); % 计算累积直方图
normalized_histogram = cumulative_histogram / numel(gray_img); % 归一化
```
5. 对图像的像素值进行映射
```matlab
new_img = normalized_histogram(gray_img + 1); % 映射像素值
```
6. 显示原始图像和均衡化后的图像
```matlab
subplot(1, 2, 1); % 创建子图
imshow(gray_img); % 显示原始图像
title('原始图像');
subplot(1, 2, 2); % 创建子图
imshow(new_img); % 显示均衡化后的图像
title('均衡化后的图像');
```
通过以上代码,我们可以实现对图像的直方图均衡化处理。代码中通过imread函数读取图像,然后转换为灰度图,计算图像的直方图并计算累积直方图,最后对图像的像素值进行映射。最终通过subplot和imshow函数将原始图像和均衡化后的图像显示出来。这样,我们就可以直观地观察到均衡化处理对图像的效果改善。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)