日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

MATLAB数字图像处理

發(fā)布時間:2024/8/1 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MATLAB数字图像处理 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

MATLAB數(shù)字圖像處理

【課程總結(jié)】

彩色圖像

方塊彩色圖像顯示

  • MATLAB中調(diào)色板色彩強度[0,1],0代表最暗,1代表最亮。
    常用顏色的RGB值:

顏色 R G B 顏色 R G B
黑 0 0 0 洋紅 1 0 1白 1 1 1 青藍(lán) 0 1 1紅 1 0 0 天藍(lán) 0.67 0 1綠 0 1 0 橘黃 1 0.5 0藍(lán) 0 0 1 深紅 0.5 0 0黃 1 1 0 灰 0.5 0.5 0.5
  • 例:在黑色背景上,繪出下面方塊中的彩色。顯示RGB圖像及其HSI分量圖像
clear all,close all,clc % RGB=cat(3,R,G,B); RGB=zeros(400,512,3) % R RGB(26:125,15:165,1)=1; RGB(26:125,182:332,1)=1; RGB(151:250,15:165,1)=1; RGB(151:250,349:500,1)=1; % G RGB(26:125,182:332,2)=1; RGB(151:250,182:332,2)=1; RGB(276:375,182:332,2)=1; RGB(151:250,349:500,2)=1; % B RGB(26:125,349:500,3)=1; RGB(151:250,15:165,3)=1; RGB(151:250,182:332,3)=1; RGB(151:250,349:500,3)=1;figure; imagesc(RGB); axis off; figure(2) subplot(221) imagesc(RGB) title('\fontsize{20}the original image') axis off subplot(222) imagesc(RGB(:,:,1)) colormap(gray) title('\fontsize{20}R component') axis off subplot(223) imagesc(RGB(:,:,2)) colormap(gray) title('\fontsize{20}G component') axis off subplot(224) imagesc(RGB(:,:,3)) colormap(gray) title('\fontsize{20}B component') axis off HSI=rgb2hsi(RGB); H=HSI(:,:,1); S=HSI(:,:,2); I=HSI(:,:,3); figure(3) subplot(221) imagesc(RGB) title('\fontsize{20}the original image') axis off subplot(222) imagesc(H) colormap(gray) title('\fontsize{20}Hue component') axis off subplot(223) imagesc(S) colormap(gray) title('\fontsize{20}Saturation component') axis off subplot(224) imagesc(I) colormap(gray) title('\fontsize{20}Intensity component') axis off


彩色變換

RGB—>HIS HIS = rgb2hsi(RGB);
HIS—>RGB RGB = hsi2rgb(HSI);通常在對HIS三分量進(jìn)行操作后重新合成,顯示合成的圖片,需要將其轉(zhuǎn)化位RGB形式顯示

三個分量分離,對某一個分量進(jìn)行增強后顯示R = RGB(:,:,1),G = RGB(:,:,2),B = RGB(:,:,3);

H = HSI(:,:,1),S = HSI(:,:,2),I = HSI(:,:,3);

分量合成 RGB=cat(3,R,G,B)
HIS=cat(3,H,S,I);顯示時,需要先轉(zhuǎn)換成RGB在顯示

  • 例:針對低對比度彩色圖像,分別顯示其色調(diào)、飽和度和亮度分量;使用圖像增強方法改進(jìn)亮度分量圖像的對比度,將增強后的亮度分量與色調(diào)、飽和度分量結(jié)合在一起,得到對比度增強彩色圖像。顯示增強前后的彩色圖像。
clear all close all clcc=imread('fig3_4.jpg'); HSI=rgb2hsi(c); H=HSI(:,:,1); S=HSI(:,:,2); I=HSI(:,:,3); m=mean2(I); E=0.9; I1=1./(1+(m./(I+eps)).^E);%改變亮度分量 I1=mat2gray(I1); g=cat(3,H,S,I1); g=hsi2rgb(g); figure; subplot(211) imagesc(c) title('\fontsize{10}the original image') axis off subplot(212) imagesc(g) title('\fontsize{10}Enhanced image') axis off

灰度變換、平滑、飽和度、邊緣銳化

x=imread(‘x.jpg’);
x=rbg2gray(x); %轉(zhuǎn)成灰度圖像
k=medfilt2(x); %中值濾波,默認(rèn)為3X3矩陣
figure, imshow(k);

medfilt2(A,[M,N]):使用 M X N 的模板讀A矩陣做中值濾

空間域增強

灰度變化

1.線性變換

f=imread('Fig3.10(b).jpg'); f=im2double(f); imshow(f); figure;imhist(f); a=min(f(:)); b=max(f(:)); g=1*(f-a)/(b-a); figure; imshow(g); figure;imhist(g);

2.2. 分段線性變換

  • 例:使用以下命令創(chuàng)建一幅暗圖像
    “c=imread(‘cameraman.tif’);[x,map]=gray2ind?;”使用分段線性灰度變換改進(jìn)圖像的對比度
clear all close all clcc=imread('D:\Program Files\MATLAB\R2011b\toolbox\images\imdemos\cameraman.tif'); [x,map]=gray2ind(c); r=im2double(x); r1=0.1;r2=0.28; s1=0.05;s2=0.9; k1=s1/r1;k2=(s2-s1)/(r2-r1);k3=(1-s2)/(1-r2); s=k1*r.*(r<=r1)+(k2*(r-r1)+s1).*(r>=r1 & r<r2)...+(k3*(r-r2)+s2).*(r>=r2); rr=0:0.01:1; ss=k1*rr.*(rr<r1)+(k2*(rr-r1)+s1).*(rr>=r1 & rr<r2)...+(k3*(rr-r2)+s2).*(rr>=r2); subplot(221) imhist(r) title('\fontsize{10}輸入圖像的直方圖') subplot(222) plot(rr,ss) title('\fontsize{10}灰度變換曲線') grid on subplot(223) imshow(x) title('\fontsize{10}輸入圖像') subplot(224) imshow(s) title('\fontsize{10}輸出圖像')

3.灰度反轉(zhuǎn)變換

r=imread('H:\data\thry\chpt3\Fig3.04(a).jpg'); r=double(r); mx=max(r(:)); s=mx-r; subplot(121) imshow(r,[]) title('\fontsize{40}Input image') subplot(122) imshow(s,[]) title('\fontsize{40}Output image')

直方圖

imhist(f):顯示f圖像的直方圖

  • 例1:下面表格給出了一幅圖像中[0,7]范圍內(nèi)的每個灰度級對應(yīng)的像素數(shù)。繪制這些灰度級對應(yīng)的直方圖。接著執(zhí)行直方圖均衡化,繪制均衡化后的直方圖。
    0 1 2 3
    3244 3899 4559 2573
    4 5 6 7
    1428 530 101 50
clear all close all clcr=0:7; L=length(r); nr=[3244 3899 4559 2573 1428 530 101 50]; n=sum(nr); pr=nr./n; Tr=cumsum(pr); s=r; ps=zeros(1,L); for r1=0:L-1s1=round(Tr(r1+1)*(L-1));ps(s1+1)=ps(s1+1)+pr(r1+1); end subplot(121) stem(r,pr) xlabel('r') ylabel('p_r(r)') title('Histogram before equalization') subplot(122) stem(s,ps) xlabel('s') ylabel('p_s(s)') title('Histogram after equalization')
  • 例2:下面圖像包含[0,19]范圍內(nèi)的灰度級。試?yán)L制直方圖均衡化前后的圖像及其直方圖

clear all close all clcf=[12 6 5 13 14 14 16 1511 10 8 5 8 11 14 149 8 3 4 7 12 18 1910 7 4 2 10 12 13 1716 6 13 13 16 19 19 1712 10 14 15 18 18 16 1411 8 10 12 14 13 14 158 6 3 7 9 11 12 12] r=0:7; for k=rg=(f==k);nr(k+1)=sum(g(:)); end n=sum(nr); pr=nr/n Tr=cumsum(pr) s=round(Tr*7) ps=zeros(1,8); f_equal=zeros(size(f)); for k=rps(s(k+1)+1)=ps(s(k+1)+1)+pr(k+1);f_equal(f==k)=s(k+1); end ps f_equal subplot(221) imshow(f,[]) title('Image before equalization') subplot(222) stem(r,nr) xlabel('r') ylabel('p_r(r)') title('Histogram before equalization') subplot(223) imshow(f_equal,[]) title('Image after equalization') subplot(224) stem(0:7,ps) xlabel('s') ylabel('p_s(s)') title('Histogram after equalization')
  • 例3:使用下面命令創(chuàng)建一幅暗圖像
    “c=imread(‘cameraman.tif’); [x,map]=gray2ind?; ”矩陣x是攝影師圖像的一個暗版本。對該圖像使用直方圖均衡化處理,比較均衡化圖像與原圖像。
c=imread('cameraman.tif'); [x,map]=gray2ind(c); subplot(221),imshow(x); title('the original image'); subplot(223) imhist(x); title('histogram') ylim('auto') g=histeq(x,256); subplot(222),imshow(g) title('image after equalization of histogram') subplot(224),imhist(g) title('histogram after equalization')

空間域銳化濾波器

拉普拉斯算子:
w4=[0 1 0;1 -4 1;0 1 0]; 中心系數(shù)為-4的拉普拉斯算子 fspecial(‘laplacian’,0)
w8=[1 1 1;1 -8 1;1 1 1]; 中心系數(shù)為-8的拉普拉斯算子
f=im2double(f);
g1=imfilter(f,w4,‘replicate’);
g4=f-4*g1;imshow(g4,[])

1)利用Sobel算子銳化數(shù)字?jǐn)?shù)字圖像, 如:
i=imread(‘104_8.tif’);
h=[1,2,1;0,0,0;-1,-2,-1];%Sobel算子
j=filter2(h,i);
2)利用拉氏算子銳化數(shù)字?jǐn)?shù)字圖像, 如:
i=imread(‘104_8.tif’);
j=double(i);
h=[0,1,0;1,-4,0;0,1,0];%拉氏算子
k=conv2(j,h,‘same’);
m=j-k;

傅里葉變換

性質(zhì)(主要:平移不變性)

變換

頻率域圖像增強

平滑(3種)

1 理想低通濾波器
2 巴特沃斯低通濾波器
3 高斯低通濾波器

  • 例:打開cameraman.tif圖像:使用如下濾波器對圖像進(jìn)行頻域濾波:
    (a) 理想低通濾波器,
    (b) 巴特沃斯低通濾波器,
    ? 高斯低通濾波器。
    人臉仍然能夠被分辨的理想低通濾波器的最小半徑是多少?

理想低通濾波器

clc;clear all;close all;f=imread('D:\Program Files\MATLAB\R2011b\toolbox\images\imdemos\cameraman.tif'); subplot(221); imshow(f,[]); title('\fontsize{10}original image'); [M,N]=size(f); F=fftshift(fft2(f)); u=1:M; v=1:N; [V,U]=meshgrid(v,u); D=sqrt((U-floor(M/2)).^2+(V-floor(N/2)).^2); %The coordinate on the left top corner is (1,1)£? % the center is (M/2,N/2) H=zeros(size(f)); k=2; for D0=[15 30 50]H(D<D0)=1;G=F.*H;g=ifft2(ifftshift(G));subplot(2,2,k)imshow(real(g),[]); title(['\fontsize{10}ideal low pass filter with radius<',num2str(D0)]);k=k+1; end

人臉仍然能夠被分辨的理想低通濾波器的最小半徑是50

巴特沃斯低通濾波器

clc;clear all;close all;f=imread('D:\Program Files\MATLAB\R2011b\toolbox\images\imdemos\cameraman.tif'); subplot(231); imshow(f,[]); title('\fontsize{10}original image'); [M,N]=size(f); F=fftshift(fft2(f)); u=1:M; v=1:N; [V,U]=meshgrid(v,u); D=sqrt((U-floor(M/2)).^2+(V-floor(N/2)).^2); H=zeros(size(f)); k=2; n=2; for D0=[5 15 30 80 230]H=1./(1+(D./D0).^(2*n));G=F.*H; %low pass filter on frequency domaing=ifft2(ifftshift(G));subplot(2,3,k)k=k+1;imshow(real(g),[]); title({'\fontsize{10}Butterworth low pass';...['\fontsize{10}filter with radius<',num2str(D0)]}); end

高斯低通濾波器

clc;clear all;close all;f=imread('D:\Program Files\MATLAB\R2011b\toolbox\images\imdemos\cameraman.tif'); subplot(231); imshow(f,[]); title('\fontsize{10}original image'); [M,N]=size(f); F=fftshift(fft2(f)); u=1:M; v=1:N; [V,U]=meshgrid(v,u); D=sqrt((U-floor(M/2)).^2+(V-floor(N/2)).^2); H=zeros(size(f)); k=2; n=2; for D0=[5 15 30 80 230]H=exp(-D.^2./(2*D0.^2));G=F.*H; %low pass filter on frequency domaing=ifft2(ifftshift(G));subplot(2,3,k)k=k+1;imshow(real(g),[]);title({'\fontsize{10}Gaussian lowpass';...['\fontsize{10}filter with radius<',num2str(D0)]}); end

銳化(4種)

圖像復(fù)原

模型

模糊模型:大氣模糊、運動模糊

大氣模糊

f=imread('e:\chenpc\data\thry\chpt5\Fig5.25(a).jpg'); f=im2double(f); subplot(221); imshow(f,[]) title('\fontsize{30}original image') F=fftshift(fft2(f)); [M,N]=size(F); u=1:M; v=1:N; [V,U]=meshgrid(v,u); m=2; for k=[0.0025 0.001 0.00025] %severe turbulenceH=exp(-k*((U-floor(M/2)).^2+(V-floor(N/2)).^2).^(5/6));G=F.*H;g=real(ifft2(ifftshift(G))); subplot(2,2,m); imshow(g,[])if k==0.0025title('\fontsize{30}severe turbulence')save h:\data\thry\chpt5\Fig5.25(b).mat gelseif k==0.001title('\fontsize{30}mild turbulence')elsetitle('\fontsize{30}low turbulence') endm=m+1; end

運動模糊

[M,N]=size(f); u=1:M; v=1:N; [V,U]=meshgrid(v,u); a=0.1*M;b=0.1*N;T1=1;T2=3; t1=pi*((U-floor(M/2))*a/M); t2=pi*((V-floor(N/2))*b/N); H=(T1*sin(t2+eps).*exp(-j*t2)./(t2+eps))+(T2*sin(t1+eps).*exp(-j*t2).*exp(-j*(t1+t2))./(t1+eps)); F=fftshift(fft2(f)); G=F.*H; g=real(ifft2(ifftshift(G))); subplot(132) imshow(g,[])A

復(fù)原方式

最小約束平方濾波

clear all close all clc f=imread('e:\chenpc\data\thry\chpt5\Fig5.26(a).jpg'); f=im2double(f); [M,N]=size(f); u=1:M; v=1:N; [V,U]=meshgrid(v,u); a=0.1*M; b=0.1*N; T=1; tmp=pi.*((U-(floor(M/2)+1))*a/M+(V-(floor(N/2)+1))*b/N); H=sin(tmp+eps).*exp(-j*tmp).*T./(tmp+eps); F=fftshift(fft2(f)); G=F.*H; g=real(ifft2(ifftshift(G))); %produce the image blurred by motionm=1; Sf=abs(fftshift(fft2(f))).^2; %power spectrum of signal p=[0 1 0;1 -4 1;0 1 0]; %Laplacian operator P=fftshift(fft2(p,M,N)); %frequency spectrum of Laplacian operator k1=5; for sig=[650 65 0.0065]noise=imnoise(zeros(M,N),'gaussian',0,sig); %add Gaussian noisegb=g+noise;subplot(3,3,m)imshow(gb,[])title(['Gaussian noise(\sigma=',num2str(sig),')'])G=fftshift(fft2(gb));Sn=abs(fftshift(fft2(noise))).^2; %power spectrum of noise k=Sn./Sf;F=conj(H).*G./(abs(H).^2+k); %Wiener filterfr=real(ifft2(ifftshift(F)));subplot(3,3,m+1)imshow(fr,[])title('Wiener filter')F=conj(H).*G./(abs(H).^2+k1.*abs(P).^2+eps);%Constrained least square restorationfr=real(ifft2(ifftshift(F)));subplot(3,3,m+2)imshow(fr,[])title('constrained least square filter')m=m+3; end

維納濾波復(fù)原

K=eps; F=conj(H).*G./(abs(H).^2+K); f=real(ifft2(ifftshift(F))); subplot(133) imshow(f,[]) title('\fontsize{10}Wiener filter result');

形態(tài)學(xué)

4個基本操作

1.膨脹:是在二值化數(shù)字?jǐn)?shù)字圖像中“加長”或“變粗”的操作,函數(shù)imdilate執(zhí)行膨脹運算,如:
a=imread(‘104_7.tif’);%輸入二值數(shù)字?jǐn)?shù)字圖像
b=[0 1 0;1 1 1;01 0];
c=imdilate(a,b);
2.腐蝕:函數(shù)imerode執(zhí)行腐蝕,如:
a=imread(‘104_7.tif’);%輸入二值數(shù)字?jǐn)?shù)字圖像
b=strel(‘disk’,1);
c=imerode(a,b);
3.開運算:先腐蝕后膨脹稱為開運算,用imopen來實現(xiàn),如:
a=imread(‘104_8.tif’);
b=strel(‘square’,2);
c=imopen(a,b);
4.閉運算:先膨脹后腐蝕稱為閉運算,用imclose來實現(xiàn),如:
a=imread(‘104_8.tif’);
b=strel(‘square’,2);
c=imclose(a,b);

重構(gòu)

腐蝕

se=ones(15,1); marker=imerode(f,se); restore=imreconstruct(marker,f); imshow(restore,[])

三種尋找mark的方式

相關(guān)

clear all;close all;clcf=imread('Fig0903(a).tif'); f=im2double(f); imshow(f,[]) title('Image including objects') [mf,nf]=size(f);mask=roipoly(f); %ê??ˉ??è???àa?? title('image') b=f.*mask; [r,c,v]=find(b~=0); r1=min(r);r2=max(r); c1=min(c);c2=max(c); h=b(r1:r2,c1:c2);% Object [mh,nh]=size(h); figure M=mf+mh-1; N=nf+nh-1; f(M,N)=0; %pad zeros to avoid aliasing of adjacent period to subplot(221) imshow(f,[]) title('image') subplot(222) imshow(h,[]) title('Object') h(M,N)=0; %pad zeros to avoid aliasing of adjacent period to F=fft2(f); H=fft2(h); corr=real(ifft2(F.*conj(H))); [r,c]=find(corr==max(corr(:))); subplot(223) imshow(f,[]) hold on plot(c(1),r(1),'ws') mask=zeros(size(f)); mask(r(1):r(1)+mh,c(1):c(1)+nh)=1; object=(f & mask); subplot(224) imshow(object,[])

擊中擊不中

bwhitmiss(A,B1,B2) 先用結(jié)構(gòu)元素B1對A進(jìn)行腐蝕,然后再用結(jié)構(gòu)元素B進(jìn)行腐蝕

mask=roipoly(f); %手動選取輪廓線 g=mask.*f; [r,c]=find(g); g=g(min(r):max(r),min(c):max(c)); B1=g; B2=~g; marker=bwhitmiss(f,B1,B2); restore=imreconstruct(marker,f); imshow(restore,[])

填孔洞

g=imfill(f,‘holes’);
%fill the holes surrounded by stroks of characters
subplot(335)
imshow(g,[])
%display the image after filling holes
title(’(e)Holes filled’)

手動輪廓線

clear all;close all;clc f=imread('F:\picture process\t3.jpg'); f=im2double(f); f=im2bw(f,0.5); figure imshow(f,[]) mask=roipoly(f); %ê??ˉ??è???àa?? g=mask.*f; [r,c,v]=find(g~=0); h=g(min(r):max(r),min(c):max(c)); [mh,nh]=size(h); figure imshow(h,[]) B1=[0 0 0 0;0 1 1 0;0 1 1 0;0 0 0 0]; B2=~B1; marker=bwhitmiss(f,B1,B2); restore=imreconstruct(marker,f); figure imshow(restore,[])

總結(jié)

以上是生活随笔為你收集整理的MATLAB数字图像处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 少妇裸体挤奶汁奶水视频 | 日本激情网站 | 欧美精品自拍视频 | 国产免费观看视频 | 青草视频免费在线观看 | 少妇高潮惨叫久久久久久 | 亚洲色图第三页 | 中文字幕无码乱码人妻日韩精品 | 色天堂在线视频 | 九九黄色片 | 国产精品天美传媒入口 | 欧美性猛交xxxx乱大交俱乐部 | 福利片在线观看 | 国产999视频 | 久草这里只有精品 | 欧美一区二区三区四区在线 | 波多野结衣在线一区 | 污污的网站在线免费观看 | 谁有av网址 | 国产无套内射又大又猛又粗又爽 | 精品国产乱码久久久久夜深人妻 | 亚洲欧美日韩在线播放 | 啪视频免费 | 伊人久久视频 | 国产日韩综合 | 亚洲色图视频在线 | 香蕉久久国产 | 不卡一区在线 | 欧美激情免费在线 | 自拍亚洲欧美 | 国产91熟女高潮一区二区 | 夜夜高潮夜夜爽 | 亚洲一级网 | 国产精品第一区 | 欧美性猛交 | 亚洲电影在线观看 | 99精品无码一区二区 | 怡红院久久 | 狠狠操在线观看 | 精品在线99 | 国产suv精品一区二区33 | 精品在线一区二区三区 | 亚洲精品 欧美 | 国产精品丝袜 | 草久网 | 欧美a∨亚洲欧美亚洲 | 日韩欧美在线看 | 久久天天干 | 国产精品亚洲自拍 | 色婷婷www | 欧美二区三区 | 欧美 日韩 国产 一区二区三区 | 巨大乳の揉んで乳榨り奶水 | 一二区免费视频 | 亚洲天堂日本 | 风流老熟女一区二区三区 | 亚洲va久久久噜噜噜无码久久 | 男人的天堂在线视频 | 亚洲福利专区 | 国产精品国产三级国产aⅴ无密码 | 波多野结衣三区 | 一区二区三区四区五区av | 啪啪免费视频网站 | 国产精品剧情 | 快播日韩| 欧美被狂躁喷白浆精品 | 亚洲永久免费视频 | 日韩欧美国产三级 | 国产伦精品一区二区三区高清版 | 四虎国产在线观看 | 国产视频手机在线播放 | 2021天天操| 182tv福利视频 | 午夜成人亚洲理伦片在线观看 | 国产56页| 都市激情一区 | 亚洲一区动漫 | 秋霞福利网 | 国产精品一区二区久久毛片 | 91国在线视频 | 成人黄色一区二区 | 亚洲国产免费av | 亚洲综合情 | 日韩高清精品免费观看 | 不卡视频一区二区 | 伊人9999| 韩国一区二区在线观看 | 精品一区二区精品 | 中文字幕日韩精品亚洲一区小树林 | 成人深夜免费视频 | 欧美亚洲欧美 | 在线观看免费高清视频 | 国产精品人人做人人爽 | av国语| 国产成人日韩 | 亚洲av乱码久久精品蜜桃 | 欧美日韩视频在线观看免费 | 免费av中文字幕 | 国产视频综合 |