I=imread('0294.jpg'); I=imresize(I,[300 300]); I1=RGB2Lab(I); L1 = double(I1(:,:,1)); L2 = double(I1(:,:,2)); L3 = double(I1(:,:,3)); PL1=mean(L1(:)); PL2=mean(L2(:)); PL3=mean(L3(:)); [m,n]=size(L1); for i=1:m for j=1:n LL1(i,j)=abs(L1(i,j)-PL1); end end for i=1:m for j=1:n LL2(i,j)=abs(L2(i,j)-PL2); end end for i=1:m for j=1:n LL3(i,j)=abs(L3(i,j)-PL3); end end LLL1=reshape(LL1,1,[]); SL1=std(LLL1); LLL2=reshape(LL2,1,[]); SL2=std(LLL2); LLL3=reshape(LL3,1,[]); SL3=std(LLL3); %比较标准差最大 SL=max(max(SL1,SL2),SL3); G = fspecial('gaussian', [5 5], 1); GL1=imfilter(LL1, G, 'circular'); hist=imhist(GL1)/prod(size(GL1)); G1=find(hist); H1=-hist(G1)'*log2(hist(G1)); GL2=imfilter(LL2, G, 'circular'); hist=imhist(GL2)/prod(size(GL2)); G2=find(hist); H2=-hist(G2)'*log2(hist(G2)); GL3=imfilter(LL3, G, 'circular'); hist=imhist(GL3)/prod(size(GL3)); G3=find(hist); H3=-hist(G3)'*log2(hist(G3)); %比较二维熵最小的 H=min(min(H1,H2),H3); if(SL==SL1) ZL=LL1; end if(SL==SL2) ZL=LL2; end if(SL==SL3) ZL=LL3; end if(H==H1) HL=LL1; end if(H==H2) HL=LL2; end if(H==H3) HL=LL3; end %计算初始显著图 C=0.35*ZL+0.65*HL; [Z E]=lrr(C,0.01);%全局低秩Z为低秩部分E为稀疏部分 ZZ=(C-Z).*C; figure,imshow(ZZ,[]);如何调整代码使其在处理图片时最终输出的图片不会改变大小
时间: 2023-06-15 22:04:17 浏览: 121
untile2.zip_matlab 图像处理
您可以将imresize函数中的大小参数改为原图像的大小,即:
```
I=imread('0294.jpg');
I1=RGB2Lab(I);
L1 = double(I1(:,:,1));
L2 = double(I1(:,:,2));
L3 = double(I1(:,:,3));
PL1=mean(L1(:));
PL2=mean(L2(:));
PL3=mean(L3(:));
[m,n]=size(L1);
for i=1:m
for j=1:n
LL1(i,j)=abs(L1(i,j)-PL1);
end
end
for i=1:m
for j=1:n
LL2(i,j)=abs(L2(i,j)-PL2);
end
end
for i=1:m
for j=1:n
LL3(i,j)=abs(L3(i,j)-PL3);
end
end
LLL1=reshape(LL1,1,[]);
SL1=std(LLL1);
LLL2=reshape(LL2,1,[]);
SL2=std(LLL2);
LLL3=reshape(LL3,1,[]);
SL3=std(LLL3);
%比较标准差最大
SL=max(max(SL1,SL2),SL3);
G = fspecial('gaussian', [5 5], 1);
GL1=imfilter(LL1, G, 'circular');
hist=imhist(GL1)/prod(size(GL1));
G1=find(hist);
H1=-hist(G1)'*log2(hist(G1));
GL2=imfilter(LL2, G, 'circular');
hist=imhist(GL2)/prod(size(GL2));
G2=find(hist);
H2=-hist(G2)'*log2(hist(G2));
GL3=imfilter(LL3, G, 'circular');
hist=imhist(GL3)/prod(size(GL3));
G3=find(hist);
H3=-hist(G3)'*log2(hist(G3));
%比较二维熵最小的
H=min(min(H1,H2),H3);
if(SL==SL1)
ZL=LL1;
end
if(SL==SL2)
ZL=LL2;
end
if(SL==SL3)
ZL=LL3;
end
if(H==H1)
HL=LL1;
end
if(H==H2)
HL=LL2;
end
if(H==H3)
HL=LL3;
end
%计算初始显著图
C=0.35*ZL+0.65*HL;
[Z E]=lrr(C,0.01);%全局低秩Z为低秩部分E为稀疏部分
ZZ=(C-Z).*C;
figure,imshow(ZZ,[]);
```
这样就可以保持输出图片与原图像的大小一致。
阅读全文