clear all; clc; source_img=imread('C:\Users\LENOVO\Desktop\yes.jpg');%读取图片 [m,n,p]=size(source_img);%计算图片的行数列数层数 %==========从RGB转换到HSV======================= hsv_img=rgb2hsv(source_img); h=hsv_img(:,:,1); s=hsv_img(:,:,2); v=hsv_img(:,:,3); figure; subplot(221);imshow(source_img); subplot(222);imshow(h); subplot(223);imshow(s); subplot(224);imshow(v); %============V分量小波包分解======================================== [cc,ss]=wavedec2(v,1,'haar'); cA=appcoef2(cc,ss,'haar',1); %cc:小波分解的小波系数矩阵;ss:小波分解对应的尺度矩阵;分解的层数为1 cH=detcoef2('h',cc,ss,1); %h:提取水平高频;v:垂直高频;d:对角高频 cV=detcoef2('v',cc,ss,1); cD=detcoef2('d',cc,ss,1); cA1=mapminmax(cA,0,1);%归一化处理 figure; subplot(221);imshow(cA1,[]);title('(a) 近似分量cA'); subplot(222);imshow(cH,[]);title('(b) 细节分量cH'); subplot(223);imshow(cV,[]);title('(c) 细节分量cV'); subplot(224);imshow(cD,[]);title('(d) 细节分量cD'); %=============近似分量cA双边滤波================================== w = 3; % bilateral filter half-width sigma = [3 0.2]; % bilateral filter standard deviations cA2=bfilter2(cA1,w,sigma); %双边滤波 hsize=15; sigma1=15; sigma2=85; sigma3=265; H1=fspecial('gaussian',hsize,sigma1); H2=fspecial('gaussian',hsize,sigma2); H3=fspecial('gaussian',hsize,sigma3); img1=conv2(v,H1,'same'); img2=conv2(v,H2,'same'); img3=conv2(v,H3,'same'); imggaus=1/3*img1+1/3*img2+1/3*img3; alpha5=0.1; k5=alpha5*sum(s(:))/(m*n); vnew5=v*(1+k5)./(max(v,imggaus)+k5); X1=v(:)'; X2=vnew5(:)'; X=[X1 X2]; C=cov(X1,X2); [V,D]=eig(C); diagD=diag(D); if diagD(1)>diagD(2) V1=V(:,1); else V1=V(:,2); end w1=V1(1)/(V1(1)+V1(2)); w2=V1(2)/(V1(1)+V1(2)); recon_set=w1*v+w2*vnew5; %==============HSV转换RGB========================================= hsv(:,:,1)=h; hsv(:,:,2)=s; hsv(:,:,3)=recon_set; rgb_img=hsv2rgb(hsv); figure; subplot(121);imshow(source_img);%显示原图 subplot(122);imshow(rgb_img);%显示增强后的图 根据代码写结果说明及分析
时间: 2023-08-23 18:03:30 浏览: 139
根据代码,您的实验是对低照度图像进行增强。以下是代码的结果说明及分析:
1. 代码中读取了一张名为 "yes.jpg" 的图像,并将其转换为HSV颜色空间。
2. 代码将HSV图像分解为亮度分量(V通道)和色调分量(H通道)以及饱和度分量(S通道)。
3. V分量进行了小波包分解,得到近似分量(cA)和细节分量(cH、cV、cD)。
4. 近似分量cA经过归一化处理,并进行了双边滤波。
5. 使用高斯滤波器对V分量进行了滤波处理,得到三个滤波后的图像img1、img2、img3,并将它们融合得到imggaus。
6. 计算一个权重参数alpha5,并根据该参数将V分量进行增强处理,得到vnew5。
7. 进行主成分分析(PCA),将v和vnew5进行线性组合,得到重构集合recon_set。
8. 最后,将H、S、recon_set三个通道重新组合为HSV图像,并将其转换回RGB颜色空间,得到增强后的图像rgb_img。
根据这段代码,您实现了一个基于HSV颜色空间和小波包分解的低照度图像增强方法,并结合了双边滤波和主成分分析技术。通过调整权重参数和滤波器的参数,可以对图像的亮度、对比度和细节进行增强。最终的增强效果可以在显示增强后的图像rgb_img中观察到。
请注意,以上分析仅基于提供的代码进行推测,实际结果可能会有所不同。如果您有任何其他问题或需要进一步的帮助,请随时提问。
相关问题
clc clear all %% img_in = imread('0066.jpg'); m = size(img_in,1); n = size(img_in,2); img_lab = rgb2lab(img_in); img_L_mean = mean(mean(img_lab(:,:,1))); img_a_mean = mean(mean(img_lab(:,:,2))); img_b_mean = mean(mean(img_lab(:,:,3))); %% %高斯滤波 img_R = img_in(:,:,1); img_G = img_in(:,:,2); img_B = img_in(:,:,3); w = fspecial('gaussian',[7 7]); img_R_blur = imfilter(img_R,w); img_G_blur = imfilter(img_G,w); img_B_blur = imfilter(img_B,w); img_blur = cat(3,img_R_blur,img_G_blur,img_B_blur); figure('name','滤波') imshow(img_blur) img_lab_blur = rgb2lab(img_blur); %% %计算显著图 Sd = zeros(m,n); for i = 1:m for j = 1:n Sd(i,j) = sqrt((img_L_mean - img_lab_blur(i,j,1))^2 + (img_a_mean - img_lab_blur(i,j,2))^2 + (img_b_mean - img_lab_blur(i,j,3))^2); end end %归一化 Sd_normalized = figure_normalize(Sd); imwrite(Sd_normalized,'FT_saliency.jpg') figure imshow(Sd_normalized) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end运行代码时报错错误: 非法使用保留关键字 "end"。改进代码
代码中的错误是因为您没有正确定义 `figure_normalize` 函数,导致程序无法执行。此外,您应该将 `end` 改为 `endfor` 或 `endfunction`,以正确结束循环或函数定义。以下是改进后的代码:
```
clc
clear all
img_in = imread('0066.jpg');
m = size(img_in,1);
n = size(img_in,2);
img_lab = rgb2lab(img_in);
img_L_mean = mean(mean(img_lab(:,:,1)));
img_a_mean = mean(mean(img_lab(:,:,2)));
img_b_mean = mean(mean(img_lab(:,:,3)));
%% %高斯滤波
img_R = img_in(:,:,1);
img_G = img_in(:,:,2);
img_B = img_in(:,:,3);
w = fspecial('gaussian',[7 7]);
img_R_blur = imfilter(img_R,w);
img_G_blur = imfilter(img_G,w);
img_B_blur = imfilter(img_B,w);
img_blur = cat(3,img_R_blur,img_G_blur,img_B_blur);
figure('name','滤波')
imshow(img_blur)
img_lab_blur = rgb2lab(img_blur);
%% %计算显著图
Sd = zeros(m,n);
for i = 1:m
for j = 1:n
Sd(i,j) = sqrt((img_L_mean - img_lab_blur(i,j,1))^2 + (img_a_mean - img_lab_blur(i,j,2))^2 + (img_b_mean - img_lab_blur(i,j,3))^2);
endfor
endfor
%归一化
Sd_normalized = normalize(Sd);
imwrite(Sd_normalized,'FT_saliency.jpg')
figure
imshow(Sd_normalized)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function out = normalize(in)
out = (in - min(in(:))) ./ (max(in(:)) - min(in(:)));
endfunction
```
clc; clear all; img_in = imread('ILSVRC2017_test_00000237.jpg'); m = size(img_in,1); n = size(img_in,2); img_lab = rgb2lab(img_in); img_L_mean = mean(mean(img_lab(:,:,1))); img_a_mean = mean(mean(img_lab(:,:,2))); img_b_mean = mean(mean(img_lab(:,:,3))); %高斯滤波 img_R = img_in(:,:,1); img_G = img_in(:,:,2); img_B = img_in(:,:,3); w = fspecial('gaussian',[7 7]); img_R_blur = imfilter(img_R,w); img_G_blur = imfilter(img_G,w); img_B_blur = imfilter(img_B,w); img_blur = cat(3,img_R_blur,img_G_blur,img_B_blur); figure('Name','滤波'); imshow(img_blur); img_lab_blur = rgb2lab(img_blur); %计算显著图 Sd = zeros(m,n); for i = 1:m for j = 1:n Sd(i,j) = sqrt((img_L_mean - img_lab_blur(i,j,1))^2 + (img_a_mean - img_lab_blur(i,j,2))^2 + (img_b_mean - img_lab_blur(i,j,3))^2); end end %归一化 Sd_normalized = figure_normalize(Sd); imwrite(Sd_normalized,'FT_saliency.jpg'); figure; imshow(Sd_normalized); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function Out_image = figure_normalize(In_image) o_max_image = max(max(In_image)); o_min_image = min(min(In_image)); Out_image = double(In_image - o_min_image)/double(o_max_image - o_min_image); end运行该代码报错未定义函数或变量 'figure_normalize'。
这个错误是因为你使用了一个名为`figure_normalize`的函数,但是你的代码中并没有定义这个函数。你需要自己编写这个函数并将其添加到代码中。
下面是一个可能的`figure_normalize`函数的示例,你可以将其添加到你的代码中:
```
function Out_image = figure_normalize(In_image)
o_max_image = max(max(In_image));
o_min_image = min(min(In_image));
Out_image = double(In_image - o_min_image)/double(o_max_image - o_min_image);
end
```
注意:如果你使用的是 MATLAB 的版本较新,可能会有现成的函数可以实现这个功能,例如`imadjust`函数。你可以查看 MATLAB 的文档进行了解。
阅读全文