图像复原与重建
图像复原技术的主要目的是预先确定的目标来改善图像,尽管两者有相重叠的领域,但图像增强主要是主观处理,而图像复原则大部分是客观处理的。
r = imnoise2('gaussian',100000,1,0,1);
bins = 100;
hist(r,bins)
title('gaussian')
r = imnoise2('uniform',100000,1,0,1);
bins = 100;
figure,hist(r,bins)
title('uniform')
r = imnoise2('salt & pepper',1000,1,0.1,0.27);
bins = 100;
figure,hist(r,bins)
title('salt & pepper')
r = imnoise2('lognormal',100000,1);
bins = 100;
figure,hist(r,bins)
title('lognormal')
r = imnoise2('rayleigh',100000,1,0,1);
bins = 100;
figure,hist(r,bins)
title('rayleigh')
r = imnoise2('exponential',100000,1);
bins = 100;
figure,hist(r,bins)
title('exponential')
r = imnoise2('erlang',1000,1);
bins = 100;
figure,hist(r,bins)
title('erlang')
r = imnoise2('erlang',1000,1);
bins = 100;
figure,hist(r,bins)
title('erlang')
C = [0 64; 0 128; 32 32; 64 0; 128 0; -32 32];
[r,R,S] = imnoise3(512, 512, C);
imshow(S,[])
title('[6个]指定冲击的正弦噪声周期频谱[1]')
imshow(r,[])
title('[6个]相应的正弦噪声周期模式[1]')
% S1 = fftshift(S);
% imshowMy(S1,[])
% figure,mesh(S)
C1 = C/2;
[r1,R1,S1] = imnoise3(512, 512, C1);
imshow(S1,[]),title('[6个]指定冲击的正弦噪声周期频谱[2]')
imshow(r1,[]),title('[6个]相应的正弦噪声周期模式[2]')
C2 = [6 32; -2 2];
[r2,R2,S2] = imnoise3(512, 512, C2);
imshow(S2,[]),title('[2个]指定冲击的正弦噪声周期频谱[3]')
imshow(r2,[]),title('[2个]相应的正弦噪声周期模式[3]')
A = [1 5];
[r3,R3,S3] = imnoise3(512, 512, C2, A);
imshow(S3,[]) %有两个不清楚的点,因为其振幅较小
title('[2个][使用非默认的不同振幅]指定冲击的正弦噪声周期频谱[4]')
imshow(r3,[])
title('[2个][使用非默认的不同振幅]相应的正弦噪声周期模式[4]')
subplot(3, 2, 1), imshow(S,[]),title('[6个]指定冲击的正弦噪声周期频谱[1]')
subplot(3, 2, 2), imshow(r,[]),title('[6个]相应的正弦噪声周期模式[1]')
subplot(3, 2, 3), imshow(S1,[]),title('[6个]指定冲击的正弦噪声周期频谱[2]')
subplot(3, 2, 4), imshow(r1,[]),title('[6个]相应的正弦噪声周期模式[2]')
subplot(3, 2, 5), imshow(r2,[]),title('[2个][使用非默认的不同振幅]指定冲击的正弦噪声周期频谱[4]')
subplot(3, 2, 6), imshow(r3,[]),title('[2个][使用非默认的不同振幅]相应的正弦噪声周期模式[4]');
f = imread("D:\数字信号处理图片\DIP3E_CH05_Original_Images\Fig0508(a)(circuit-board-pepper-prob-pt1).tif");
imshow(f),title('原始图像')
[M,N] = size(f);
R = imnoise2('salt & pepper',M,N,0.1,0);
c = find(R == 0);
gp = f;
gp(c) = 0;
imshow(gp),title('被概率为0.1的胡椒噪声污染的图像')
R = imnoise2('salt & pepper',M,N,0,0.1);
c = find(R == 1);
gs = f;
gs(c) = 255;
imshow(gs),title('被概率为0.1的盐粒噪声污染的图像')
fp = spfilt(gp,'chmean',3,3,1.5);
imshow(fp),title('用阶为Q=1.5的3*3反调和滤波器对[被概率为0.1的胡椒噪声污染的图像]滤波的结果')
fs = spfilt(gs,'chmean',3,3,-1.5);
imshow(fs),title('用阶为Q=-1.5的3*3反调和滤波器对[被概率为0.1的盐粒噪声污染的图像]滤波的结果')
fpmax = spfilt(gp,'max',3,3);
imshow(fpmax),title('用3*3最大滤波器对[被概率为0.1的胡椒噪声污染的图像]滤波的结果')
fsmin = spfilt(gs,'min',3,3);
imshow(fsmin),title('用3*3最小滤波器对[被概率为0.1的盐粒噪声污染的图像]滤波的结果')
subplot(3, 3, 1), imshow(f),title('原始图像')
subplot(3, 3, 2), imshow(gp),title('被概率为0.1的胡椒噪声污染的图像')
subplot(3, 3, 3), imshow(gs),title('被概率为0.1的盐粒噪声污染的图像')
subplot(3, 3, 4), imshow(fp),title('用阶为Q=1.5的3*3反调和滤波器对[被概率为0.1的胡椒噪声污染的图像]滤波的结果')
subplot(3, 3, 5),imshow(fs),title('用阶为Q=-1.5的3*3反调和滤波器对[被概率为0.1的盐粒噪声污染的图像]滤波的结果')
subplot(3, 3, 6), imshow(fpmax),title('用3*3最大滤波器对[被概率为0.1的胡椒噪声污染的图像]滤波的结果')
subplot(3, 3, 7), imshow(fsmin),title('用3*3最小滤波器对[被概率为0.1的盐粒噪声污染的图像]滤波的结果')
f = imread("D:\数字信号处理图片\DIP3E_CH05_Original_Images\Fig0512(a)(ckt-uniform-var-800).tif");
imshow(f)
title('原始图像')
g = imnoise(f,'salt & pepper',0.25);% 噪声点有黑有白
imshow(g)
title('被概率为0.25椒盐噪声污染的图像')
f1 = medfilt2(g,[7 7],'symmetric');
imshow(f1)
title('用7*7中值滤波器对[被概率为0.25椒盐噪声污染的图像]滤波的结果')
f2 = adpmedian(g,7);
imshow(f2)
title('用Smax=7的自适应中值滤波器对[被概率为0.25椒盐噪声污染的图像]滤波的结果')
subplot(2, 2, 1), imshow(f),title('原始图像')
subplot(2, 2, 2), imshow(g),title('被概率为0.25椒盐噪声污染的图像')
subplot(2, 2, 3), imshow(f1),title('用7*7中值滤波器对[被概率为0.25椒盐噪声污染的图像]滤波的结果')
subplot(2, 2, 4), imshow(f2),title('用Smax=7的自适应中值滤波器对[被概率为0.25椒盐噪声污染的图像]滤波的结果')
1 =zeros(600,600);
g1( 100:500,250:350) = 1 ;
g2=phantom('Modified Shepp-Logan',600);
D =1.5*hypot(size(g1,1), size(g1,2))/2;
B1_line= fanbeam( g1,D,'FanSensorGeometry',...
'line','FanSensorSpacing',1,...
'FanRotationIncrement' ,0.5);
B2_arc= fanbeam( g2,D,'FanSensorGeometry','arc',...
'FanSensorSpacing',.08,'FanRotationIncrement',0.5);
P1_line=fan2para(B1_line,D,'FanRotationIncrement',0.5,...
'FanSensorGeometry','line' ,...
'FanSensorSpacing' ,1,...
'ParallelCoverage','halfcycle',...
'ParallelRotationIncrement',0.5,...
'ParallelSensorSpacing',1);
P2_arc=fan2para(B2_arc,D,'FanRotationIncrement',0.5,...
'FanSensorGeometry','arc',...
'FanSensorSpacing' ,0.08,...
'ParallelCoverage','halfcycle',...
'ParallelRotationIncrement',0.5,...
'ParallelSensorSpacing',1);
P1_line= flipud(P1_line');
P2_arc= flipud(P2_arc');
figure, imshow(P1_line,[])
figure, imshow(P2_arc,[])
subplot(2, 1, 1), imshow(P1_line,[])
f = checkerboard(8);
% imshowMy(f)
PSF = fspecial('motion',7,45)
gb = imfilter(f,PSF,'circular');
% imshowMy(gb)
noise = imnoise(zeros(size(f)),'gaussian',0,0.001);
% imshowMy(noise,[])
g = gb + noise;
imshow(g,[]),title('模糊加噪声的图像')
% ***************
fr1 = deconvwnr(g,PSF);
imshow(fr1,[]),title('简单的维纳滤波(逆滤波)后的结果')
Sn = abs(fft2(noise)).^2;
nA = sum(Sn(:))/prod(size(noise));
Sf = abs(fft2(f)).^2;
fA = sum(Sf(:))/prod(size(f));
R = nA/fA;
fr2 = deconvwnr(g,PSF,R);
imshow(fr2,[]),title('使用常数比率的维纳滤波后的结果')
NCORR = fftshift(real(ifft(Sn)));
ICORR = fftshift(real(ifft(Sf)));
fr3 = deconvwnr(g,PSF,NCORR,ICORR);
imshow(fr3,[]),title('使用自相关函数的维纳滤波后的结果')
% imshowMy(pixeldup(fr3,8))
subplot(2, 2, 1), imshow(g,[]),title('模糊加噪声的图像')
subplot(2, 2, 2), imshow(fr1,[]),title('简单的维纳滤波(逆滤波)后的结果')
subplot(2, 2, 3), imshow(fr2,[]),title('使用常数比率的维纳滤波后的结果')
subplot(2, 2, 4), imshow(fr3,[]),title('使用自相关函数的维纳滤波后的结果')
f = imread(“D:\数字信号处理图片\DIP3E_CH05_Original_Images\Fig0508(a)(circuit-board-pepper-prob-pt1).tif”);
imshow(f)
title(‘原始图像’)
g = imnoise(f,‘salt & pepper’,0.25);% 噪声点有黑有白
imshow(g)
title(‘被概率为0.25椒盐噪声污染的图像’)
f1 = medfilt2(g,[7 7],‘symmetric’);
imshow(f1)
title(‘用7*7中值滤波器对[被概率为0.25椒盐噪声污染的图像]滤波的结果’)
xlabel('\rho'),ylabel('\theta');
subplot(2, 2, 1), imshow(g1)
subplot(2, 2, 2), imshow(g2)g1=zeros(600,600);
g1(100:500,250:350)=1;
g2=phantom('Modified Shepp-Logan',600);
imshow(g1);
figure,imshow(g2);
theta=0:0.5:179.5;
[R1,xp1]=radon(g1,theta);
[R2,xp2]=radon(g2,theta);
R1=flipud(R1');
R2=flipud(R2');
figure,imshow(R1,[],'XData',xp1([1 end]),'YData',[179.5 0]);
g=phantom('Modified Shepp-Logan',600);
D = 1.5*hypot(size(g,1), size(g,2))/2;
B1 = fanbeam(g,D);
f1 =ifanbeam(B1,D);
figure, imshow(f1,[])
B2 = fanbeam(g,D,'FanRotationIncrement',0.5,...
'FanSensorSpacing',0.5);
f2 = ifanbeam(B2,D,'FanRotationIncrement',0.5,...
'FanSensorSpacing',0.5,'Filter','Hamming');
figure, imshow(f2,[])
B3 = fanbeam(g,D,'FanRotationIncrement',0.5,...
'FanSensorSpacing',0.05) ;
f3 = ifanbeam(B3,D,'FanRotationIncrement',0.5,...?
'FanSensorSpacing',0.05,'Filter','Hamming');
figure, imshow(f3,[])
subplot(1, 3, 1), imshow(f1,[])
subplot(1, 3, 2), imshow(f2,[])
subplot(1, 3, 3), imshow(f3,[])
g1 =zeros(600,600);
g1( 100:500,250:350) = 1 ;
g2=phantom('Modified Shepp-Logan',600);
D =1.5*hypot(size(g1,1), size(g1,2))/2;
B1_line= fanbeam( g1,D,'FanSensorGeometry',...
'line','FanSensorSpacing',1,...
'FanRotationIncrement' ,0.5);
B2_arc= fanbeam( g2,D,'FanSensorGeometry','arc',...
'FanSensorSpacing',.08,'FanRotationIncrement',0.5);
P1_line=fan2para(B1_line,D,'FanRotationIncrement',0.5,...
'FanSensorGeometry','line' ,...
'FanSensorSpacing' ,1,...