Matlab图像处理第四章:

4.1题目:Matlab图像处理第四章:_第1张图片在这里插入图片描述](https://img-blog.csdnimg.cn/aec689dc4cd24a31899cf57181eb9e9e.jpg)代码:clc
clearr = 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’,100000,1);bins = 100;figure,hist(r,bins)title(‘erlang’)
运行结果:Matlab图像处理第四章:_第2张图片Matlab图像处理第四章:_第3张图片Matlab图像处理第四章:_第4张图片(https://img-blog.csdnimg.cn/937913249c254e2d96088bc495bfba9a.png)
4.2题目:Matlab图像处理第四章:_第5张图片代码:clc
clearC = [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]’);
运行结果:Matlab图像处理第四章:_第6张图片4.3题目:Matlab图像处理第四章:_第7张图片代码:clc
clearr = 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’,100000,1);bins = 100;figure,hist(r,bins)title(‘erlang’)
运行结果:Matlab图像处理第四章:_第8张图片4.4题目:Matlab图像处理第四章:_第9张图片代码:clc
clearC = [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]’);
运行结果:Matlab图像处理第四章:_第10张图片4.5题目:Matlab图像处理第四章:_第11张图片代码:clc
clearf = imread(‘C:\Users\30669\Desktop\0335.tif’);imshow(f)title(‘原始含噪声图像’)[B,c,r] = roipoly(f);figure,imshow(B)[p,npix] = histroi(f,c,r);figure,bar(p,1)title(‘交互式选取区域产生的直方图’)axis tight[v,unv] = statmoments(p,2) ;X = imnoise2(‘gaussian’,npix,1, unv(1), sqrt(unv(2)) );figure,hist(X,130)title(‘使用函数[imnoise2]产生的高斯数据的直方图’)% axis([0 300 0 140])axis tight
运行结果:Matlab图像处理第四章:_第12张图片
4.6题目:Matlab图像处理第四章:_第13张图片代码:clc
clearf = imread(‘C:\Users\30669\Desktop\0335.tif’);imshow(f),title(‘原始图像’)[M,N] = size(f);R = imnoise2(‘salt & pepper’,M,N,0.1,0);c = find(R == 0);gp = f;gp© = 0;imshow(gp),title(‘被概率为0.1的胡椒噪声污染的图像’)R = imnoise2(‘salt & pepper’,M,N,0,0.1);c = find(R == 1);gs = f;gs© = 255;imshow(gs),title(‘被概率为0.1的盐粒噪声污染的图像’)fp = spfilt(gp,‘chmean’,3,3,1.5);imshow(fp),title(‘用阶为Q=1.5的33反调和滤波器对[被概率为0.1的胡椒噪声污染的图像]滤波的结果’)fs = spfilt(gs,‘chmean’,3,3,-1.5);imshow(fs),title('用阶为Q=-1.5的33反调和滤波器对[被概率为0.1的盐粒噪声污染的图像]滤波的结果’)fpmax = spfilt(gp,‘max’,3,3);imshow(fpmax),title(‘用33最大滤波器对[被概率为0.1的胡椒噪声污染的图像]滤波的结果’)fsmin = spfilt(gs,‘min’,3,3);imshow(fsmin),title('用33最小滤波器对[被概率为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的33反调和滤波器对[被概率为0.1的胡椒噪声污染的图像]滤波的结果’)subplot(3, 3, 5),imshow(fs),title('用阶为Q=-1.5的33反调和滤波器对[被概率为0.1的盐粒噪声污染的图像]滤波的结果’)subplot(3, 3, 6), imshow(fpmax),title(‘用33最大滤波器对[被概率为0.1的胡椒噪声污染的图像]滤波的结果’)subplot(3, 3, 7), imshow(fsmin),title('用33最小滤波器对[被概率为0.1的盐粒噪声污染的图像]滤波的结果’)
运行结果:Matlab图像处理第四章:_第14张图片4.7题目:Matlab图像处理第四章:_第15张图片代码:clc
clearf = imread(‘C:\Users\30669\Desktop\0326.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(‘用77中值滤波器对[被概率为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('用77中值滤波器对[被概率为0.25椒盐噪声污染的图像]滤波的结果’)subplot(2, 2, 4), imshow(f2),title(‘用Smax=7的自适应中值滤波器对[被概率为0.25椒盐噪声污染的图像]滤波的结果’)clcclearf = checkerboard(8);imshow(f),title(‘原始图像’)PSF = fspecial(‘motion’,7,45); % sum(PSF() = 1gb = imfilter(f,PSF,‘circular’);imshow(gb),title(‘使用 PSF = fspecial(motion,7,45) 模糊后的图像’)noise = imnoise(zeros(size(f)),‘gaussian’,0,0.001);imshow(noise,[]),title(‘高斯纯噪声图像’)g = gb + noise;imshow(g,[]),title(‘模糊加噪声的图像’)% imshowMy(pixeldup(f,8),[])subplot(2, 2, 1), imshow(f),title(‘原始图像’)subplot(2, 2, 2), imshow(gb),title(‘使用 PSF = fspecial(motion,7,45) 模糊后的图像’)subplot(2, 2, 3), imshow(noise,[]),title(‘高斯纯噪声图像’)subplot(2, 2, 4), imshow(g,[]),title(‘模糊加噪声的图像’)
运行结果:Matlab图像处理第四章:_第16张图片4.8题目:Matlab图像处理第四章:_第17张图片代码:clc
clearf = 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(‘使用自相关函数的维纳滤波后的结果’)
运行结果:Matlab图像处理第四章:_第18张图片4.9题目:Matlab图像处理第四章:_第19张图片代码: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]);axis xy;axis on;xlabel(’\rho’),ylabel(’\theta’);figure,imshow(R2,[],‘XData’,xp2([1 end]),‘YData’,[179.5 0]);axis xy;axis on;xlabel(’\rho’),ylabel(’\theta’);subplot(2, 2, 1), imshow(g1)subplot(2, 2, 2), imshow(g2)subplot(2, 2, 3), imshow(R1,[],‘XData’,xp1([1 end]),‘YData’,[179.5 0]);subplot(2, 2, 4), imshow(R2,[],‘XData’,xp2([1 end]),‘YData’,[179.5 0]);
运行结果:Matlab图像处理第四章:_第20张图片4.10题目:Matlab图像处理第四章:_第21张图片
代码:theta =0:0.5:179.5;
R1=radon(g1, theta);R2=radon(g2, theta);f1=iradon(R1, theta,‘none’);f2=iradon(R2, theta,‘none’);figure, imshow(f1,[])figure, imshow(f2,[])f1_ram=iradon(R1, theta);f2_ram=iradon(R2, theta);figure,imshow( f1_ram,[]);figure,imshow( f2_ram,[]);f1_hamm=iradon(R1, theta,‘hamming’);f2_hamm=iradon(R2, theta,‘hamming’);figure,imshow(f1_hamm,[]);figure,imshow(f2_hamm,[]);f1_near=iradon(R1,theta,‘nearest’);f1_lin=iradon(R1,theta,‘linear’);f1_cub=iradon(R1,theta,‘cubic’);figure,imshow(f1_near,[]);figure,imshow(f1_lin,[]);figure,imshow(f1_cub,[]);subplot(3, 4, 1), imshow(g1)subplot(3, 4, 2), imshow(g2)subplot(3, 4, 3), imshow(f1,[])subplot(3, 4, 4), imshow(f2,[])subplot(3, 4, 5), imshow (f1_ram,[])subplot(3, 4, 6), imshow (f2_ram,[])subplot(3, 4, 7), imshow (f1_hamm,[])subplot(3, 4, 8), imshow (f2_hamm,[])subplot(3, 4, 9), imshow (f1_near,[])subplot(3, 4, 10), imshow (f1_lin,[])subplot(3, 4, 11), imshow (f1_cub,[])
运行结果:Matlab图像处理第四章:_第22张图片4.11题目:Matlab图像处理第四章:_第23张图片代码: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);B1_line= flipud(B1_line’);B2_line= fanbeam( g2,D,‘FanSensorGeometry’,‘line’,…‘FanSensorSpacing’ ,1 ,‘FanRotationIncrement’ ,0.5);B2_line= flipud(B2_line’);imshow(B1_line,[]);figure, imshow(B2_line,[]);B1_arc= fanbeam( g1,D,‘FanSensorGeometry’,‘arc’,…‘FanSensorSpacing’ ,.08,‘FanRotationIncrement’ ,0.5);B2_arc=fanbeam( g2,D,‘FanSensorGeometry’,‘arc’,… ‘FanSensorSpacing’ ,.08,‘FanRotationIncrement’ ,0.5);figure,imshow( flipud(B1_arc’),[]);figure,imshow( flipud(B2_arc’),[]);subplot(2, 2, 1), imshow(B1_line,[]);subplot(2, 2, 2), imshow(B2_line,[]);subplot(2, 2, 3), imshow( flipud(B1_arc’),[]);subplot(2, 2, 4), imshow( flipud(B2_arc’),[]);
运行结果:Matlab图像处理第四章:_第24张图片4.12题目:Matlab图像处理第四章:_第25张图片代码: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,[])
运行结果:Matlab图像处理第四章:_第26张图片
4.13题目:Matlab图像处理第四章:_第27张图片代码: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,…‘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,[])subplot(2, 1, 2), imshow(P2_arc,[])
运行结果:Matlab图像处理第四章:_第28张图片

你可能感兴趣的:(图像处理)