图像分解光照分量和反射分量代码matlab
时间: 2023-11-02 16:27:27 浏览: 81
以下是一个简单的 MATLAB 代码,用于将图像分解为光照分量和反射分量:
```matlab
% 读取图像
img = imread('image.jpg');
% 将图像转换为灰度图像
gray_img = rgb2gray(img);
% 计算光照分量
light_img = imgaussfilt(gray_img, 20);
% 计算反射分量
reflect_img = gray_img - light_img;
% 显示结果
figure;
subplot(1,3,1);imshow(img);title('原图像');
subplot(1,3,2);imshow(light_img);title('光照分量');
subplot(1,3,3);imshow(reflect_img);title('反射分量');
```
该代码首先读取输入图像,然后将其转换为灰度图像。接下来,使用高斯滤波器计算光照分量。最后,通过从灰度图像中减去光照分量计算反射分量。最后,使用 subplot 函数显示原始图像、光照分量和反射分量。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)