西安交通大學(xué)大學(xué)數(shù)字圖像處理大作業(yè)_第1頁(yè)
西安交通大學(xué)大學(xué)數(shù)字圖像處理大作業(yè)_第2頁(yè)
西安交通大學(xué)大學(xué)數(shù)字圖像處理大作業(yè)_第3頁(yè)
西安交通大學(xué)大學(xué)數(shù)字圖像處理大作業(yè)_第4頁(yè)
西安交通大學(xué)大學(xué)數(shù)字圖像處理大作業(yè)_第5頁(yè)
已閱讀5頁(yè),還剩10頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、數(shù)字圖像處理目錄作業(yè)一1一 作業(yè)要求1二 源代碼1三 運(yùn)行結(jié)果3作業(yè)二5一 作業(yè)要求5二 算法描述5三 源代碼7四 運(yùn)行結(jié)果10作業(yè)一一 作業(yè)要求在圖像的空間域?yàn)V波操作中,會(huì)出現(xiàn)有部分掩膜矩陣在圖像外面的情況,所以需要給圖像先加入一個(gè)邊界,執(zhí)行完操作之后,再去掉這個(gè)邊界,保證圖像中所有的像素都參與矩陣運(yùn)算。二 源代碼byte, filter(byte,f,float,mask) int w = f.GetLength(0); int h = f.GetLength(1); byte, g = new bytew,h; int M = mask.GetLength(0)/2; int N = m

2、ask.GetLength(1)/2; for (int y=N;y<h-N;y+) for (int x=M;x<w-M;x+) float s = 0; for (int m=-M;m<=M;m+) for (int n=-N;n<=N;n+) s+=fx+m,y+n*maskM+m,N+n; gx,y = SByte(s); return g;byte SByte(double v) if (v>255) return 255; if (v<0) return 0; return (byte)v; float, averagingMask(int M,

3、int N) float, mask = new float2*M+1,2*N+1; for (int m=-M;m<=M;m+) for (int n=-N;n<=N;n+) maskM+m,N+n = 1.0f/(2*M+1)*(2*N+1); return mask;byte, addboard(byte, f,int M,int N)int w=f.GetLength(0);int h=f.GetLength(1);int gw=w+2*M;int gh=h+2*N;byte, g=new bytegw,gh;/add top board and bottom boardf

4、or(int i=0;i<N;i+)for(int j=0;j<w;j+)gM+j,i=fj,0;for(int i=0;i<N;i+)for(int j=0;j<w;j+)gM+j,i+h+N=fj,h-1;/copy the imagefor(int i=0;i<w;i+)for (int j=0;j<h;j+)gi+M,j+N=fi,j;/add left and right boardfor(int i=0;i<M;i+)for (int j=0;j<gh;j+)gi,j=gM,j;for(int i=0;i<M;i+)for (i

5、nt j=0;j<gh;j+)gw+M+i,j=ggw-1-M,j;return g;byte, removeboard(byte,f,int M,int N)int w=f.GetLength(0);int h=f.GetLength(1);int gw=w-2*M;int gh=h-2*N;byte, g=new bytegw,gh;for(int i=0;i<gw;i+)for(int j=0;j<gh;j+)gi,j=fi+M,j+N;return g;void main()byte, f = LoadImg();ShowImg("f",f);in

6、t w=f.GetLength(0);int h=f.GetLength(1);int M=10,N=20;int gw=w-2*M;int gh=h-2*N;byte, boardimage=new bytegw,gh;byte, filterimage=new bytegw,gh;boardimage=addboard(f,M,N);ShowImg("boardimage",boardimage);filterimage=filter(boardimage,averagingMask(M,N);ShowImg("result",removeboard

7、(filterimage,M,N);三 運(yùn)行結(jié)果原圖像:加邊界之后的圖像:均值濾波并且去除邊界的圖像:作業(yè)二一 作業(yè)要求給定圖像與處理結(jié)果,如圖一所示,思考算法并編程實(shí)現(xiàn)。圖一 左邊為原圖,右邊為處理結(jié)果二 算法描述Compare the result and the original image, we can see that the program change the contrast of image and enhance the edge of Lena. Consider using intensity transform and Sobel edge detection to

8、 achieve the goal. After many experiments, I choose following intensity transform function.The graph of this function is Fig 1.Fig 1 Graph of intensity transform function Use Sobel to detect the edge of the original image.Sobel in x direction can be written as the following transform matrix:SobleX=

9、Similar, Sobel in y direction can be written as the following transform matrix:SobleY= We can use SobelX and SobelY to compute the gradient image. is the value of pixels in the gradient image, is the value of pixels in image processed by SobelX, and is the value of pixels in image processed by Sobel

10、Y. In order to decrease noise, I use the following function to process gradient image:After processing, I use 0 to replace these negative values.Because the gradient image has a very high contrast, so I use intensity transform again. After that, the final result can be calculated: All the function i

11、s chosen through experiment, maybe the result isnt the same with the teachers result, but its very similar.三 源代碼byte, filter(byte,f,float,mask) int w = f.GetLength(0); int h = f.GetLength(1); int M = mask.GetLength(0)/2; int N = mask.GetLength(1)/2; byte, g = new bytew,h; for (int y=N;y<h-N;y+) f

12、or (int x=M;x<w-M;x+) float r = 0;for (int m=-M;m<=M;m+)for (int n=-N;n<=N;n+) r+=fx+m,y+n*maskM+m,N+n;gx,y=S(r); return g; byte, SobelX(byte,f) float, mask = new float3,3; mask0,0=-1; mask1,0 = 0; mask2,0 = 1; mask0,1=-2; mask1,1 = 0; mask2,1 = 2; mask0,2=-1; mask1,2 = 0; mask2,2 = 1; retu

13、rn filter(f,mask);byte, SobelY(byte,f) float, mask = new float3,3; mask0,0=-1; mask1,0 = -2; mask2,0 =-1; mask0,1= 0; mask1,1 = 0; mask2,1 = 0; mask0,2= 1; mask1,2 = 2; mask2,2 = 1; return filter(f,mask);byte S(double f) if(f>255) return 255; if(f<0) return 0; return (byte)f;byte, Scale(byte,f

14、,double a)int w = f.GetLength(0); int h = f.GetLength(1);for(int i=0;i<w;i+)for(int j=0;j<h;j+)fi,j=(byte)(fi,j*a);return f;byte, Subnum(byte,f,int a)int w = f.GetLength(0); int h = f.GetLength(1);for(int i=0;i<w;i+)for(int j=0;j<h;j+)fi,j=S(fi,j-a);return f;byte, Sub(byte,f,byte,g) int

15、w = f.GetLength(0); int h = f.GetLength(1); byte, p = new bytew,h; for(int x=0;x<w;x+) for(int y=0;y<h;y+) px,y=S(fx,y-gx,y); return p; byte, Mix(byte,fx,byte,fy) int w = fx.GetLength(0); int h = fx.GetLength(1); byte, g = new bytew,h; for (int y=0;y<h;y+) for (int x=0;x<w;x+) float px =

16、(fxx,y); float py =(fyx,y); gx,y = S(Sqrt(px*px+py*py); return g; byte, IntensityTransform(byte,f) int w = f.GetLength(0); int h = f.GetLength(1); byte, g = new bytew,h; for(int i=0;i<w;i+) for(int j=0;j<h;j+) gi,j = S(0.25*fi,j+110); return g;void main() byte , I = LoadImg(); ShowImg("Original",I); byte , I1 = IntensityTransform(I); ShowImg("IntensityTransform",I1); byte , I2 = SobelX(I); byte , I3 = SobelY(I); byte , I4 = Mix(I2,I3); ShowImg("Gradient"

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論