仅供学习 图像增强
f=imread('xxxx.jpg');
gray_f=rgb2gray(f);
gamma=0.1;
gama_f=imadjust(gray_f,[0 1],[0 1],gamma);
gamma2=0.25;
gama_f2=imadjust(gray_f,[0 1],[0 1],gamma2);
gamma3=0.5;
gama_f3=imadjust(gray_f,[0 1],[0 1],gamma3);
gamma4=0.75;
gama_f4=imadjust(gray_f,[0 1],[0 1],gamma4);
gamma5=1;
gama_f5=imadjust(gray_f,[0 1],[0 1],gamma5);
gamma6=1.25;
gama_f6=imadjust(gray_f,[0 1],[0 1],gamma6);
gamma7=1.5;
gama_f7=imadjust(gray_f,[0 1],[0 1],gamma7);
subplot(2,8,1);imshow(gray_f);
subplot(2,8,2);imshow(gama_f);
subplot(2,8,3);imshow(gama_f2);
subplot(2,8,4);imshow(gama_f3);
subplot(2,8,5);imshow(gama_f4);
subplot(2,8,6);imshow(gama_f5);
subplot(2,8,7);imshow(gama_f6);
subplot(2,8,8);imshow(gama_f7);
subplot(2,8,9);imhist(gray_f);
subplot(2,8,10);imhist(gama_f);
subplot(2,8,11);imhist(gama_f2);
subplot(2,8,12);imhist(gama_f3);
subplot(2,8,13);imhist(gama_f4);
subplot(2,8,14);imhist(gama_f5);
subplot(2,8,15);imhist(gama_f6);
subplot(2,8,16);imhist(gama_f7);
γ较大时,图片整体亮度低,但高亮度区域的对比度也更强,反之γ较小时,图片整体亮度高,但高亮度区域对比度较低。
比较分析
(1)相同滤波方法,不同模版的处理效果;
(2)相同模版,不同滤波方法的处理效果。
f=imread('xxxx.jpg');
gray_f=rgb2gray(f);
Ff=imnoise(gray_f,'salt & pepper',0.05);
W=average(Ff,3);
E=average(Ff,7);
R=average(Ff,11);
%W=med(Ff,3);
%E= med (Ff,7);
%R= med (Ff,11);
subplot(1,5,1);imshow(gray_f);
subplot(1,5,2);imshow(Ff);
subplot(1,5,3);imshow(W);
subplot(1,5,4);imshow(E);
subplot(1,5,5);imshow(R);
function Q=average(F,k)
[m,n]=size(F);
Q=uint16(zeros(m,n));Ft=uint16(F);M=uint16(ones(k,k));
h=(k+1)/2;
for i=1:m
for j=1:n
if((im-h+1)||(j>n-h+1))
Q(i,j)=Ft(i,j);continue;
end
T=Ft(i-(k-1)/2:i+(k-1)/2,j-(k-1)/2:j+(k-1)/2);
T=T.*M;
Q(i,j)=sum(T(:))/k^2;
end
end
Q=uint8(Q);
function G=med(F,k)
[m,n]=size(F);
G=uint16(zeros(m,n));Ft=uint16(F);M=uint16(ones(k,k));
h=(k+1)/2;
for i=1:m
for j=1:n
if((im-h+1)||(j>n-h+1))
G(i,j)=Ft(i,j);continue;
end
T=Ft(i-(k-1)/2:i+(k-1)/2,j-(k-1)/2:j+(k-1)/2);
T=T.*M;
T=T(:);
G(i,j)=median(T);
end
end
G=uint8(G);
clc
F=imread('cheng2.jpg');
subplot(1,3,1),imshow(F);
Dx=[1 2 1;0 0 0;-1 -2 -1];
Dy=zeros(3,3);
G=sharpen1(F,Dx,Dy);
subplot(1,3,2),imshow(G);
Dx=zeros(3,3);
Dy=[1 0 -1;2 0 -2;1 0 -1];
G=sharpen1(F,Dx,Dy);
subplot(1,3,3),imshow(G);
function G=sharpen1(F,Dx,Dy)
[m,n]=size(F);
[N,N]=size(Dx);
h=(N+1)/2;
for i=1:m
for j=1:n
if((im-h+1)||(j>n-h+1))
G(i,j)=double(F(i,j));
continue;
end
T=double(F(i-h+1:i+h-1,j-h+1:j+h-1));
T1=Dx.*T;
T2=Dy.*T;
G(i,j)=abs(sum(T1(:))+sum(T2(:)));
end
end
Min = min(G(:));
Max = max(G(:));
s=255/(Max-Min);
G = uint8((G-Min)*s);
F=imread('cheng2.jpg');
gray_f=rgb2gray(F);
subplot(1,2,1),imshow(gray_f);
D=[0 -1 0;-1 4 -1;0 -1 0];
G=laplacian(gray_f,D,false);
subplot(1,2,2),imshow(G);
function G=laplacian(F,D,Flag)
[m,n]=size(F);
[N,N]=size(D);
h=(N+1)/2;
for i=1:m
for j=1:n
if((im-h+1)||(j>n-h+1))
G(i,j)=double(F(i,j));
continue;
end
T=double(F(i-h+1:i+h-1,j-h+1:j+h-1));
t=D.*T;
G(i,j)=abs(sum(t(:)));
end
end
if(Flag==false)
Min = min(G(:));
Max = max(G(:));
s=255/(Max-Min);
G = uint8((G-Min)*s);
else
G=uint8(G+double(F));
end
f=imread('building.jpg');
Ff=imnoise(f,'salt & pepper',0.05);
W=average(Ff,3);
D=[0 -1 0;-1 4 -1;0 -1 0];
G=laplacian(W,D,true);
subplot(1,3,1),imshow(Ff);
subplot(1,3,2),imshow(W);
subplot(1,3,3),imshow(G);
f=imread('building.jpg');
D=[0 -1 0;-1 4 -1;0 -1 0];
G=laplacian(f,D,true);
Ff=imnoise(G,'salt & pepper',0.05);
W=average(Ff,3);
subplot(1,3,1),imshow(G);
subplot(1,3,2),imshow(Ff);
subplot(1,3,3),imshow(W);
f=imread('bw1.jpg');
g=imread('bw2.jpg');
W=average(f,3);
Y=average(g,3);
subplot(2,2,1);imshow(W);
subplot(2,2,2);imshow(Y);
subplot(2,2,3);imhist(W);
subplot(2,2,4);imhist(Y);
万水千山都是情,路过点个赞行不行!
希望看见的都可以帮忙点个赞!拜托了!
觉得还可以的动动手指帮忙点个赞!呜呜~