




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、數(shù)字圖像處理目錄作業(yè)一1一 作業(yè)要求1二 源代碼1三 運行結(jié)果3作業(yè)二5一 作業(yè)要求5二 算法描述5三 源代碼7四 運行結(jié)果10作業(yè)一一 作業(yè)要求在圖像的空間域濾波操作中,會出現(xiàn)有部分掩膜矩陣在圖像外面的情況,所以需要給圖像先加入一個邊界,執(zhí)行完操作之后,再去掉這個邊界,保證圖像中所有的像素都參與矩陣運算。二 源代碼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);三 運行結(jié)果原圖像:加邊界之后的圖像:均值濾波并且去除邊界的圖像:作業(yè)二一 作業(yè)要求給定圖像與處理結(jié)果,如圖一所示,思考算法并編程實現(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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 窄軌機車車輛設(shè)計與人文因素考核試卷
- 硅冶煉生產(chǎn)質(zhì)量管理與質(zhì)量檢測考核試卷
- 管道工程行業(yè)政策支持與機遇考核試卷
- 罐裝水銷售合同管理與法律風(fēng)險考核試卷
- 賽事期間的賽場氣象服務(wù)與應(yīng)急措施考核試卷
- 舞臺燈光設(shè)備在馬戲團(tuán)表演中的應(yīng)用考核試卷
- 漆器工藝品的網(wǎng)絡(luò)營銷策略考核試卷
- 船舶拆除作業(yè)人員安全培訓(xùn)考核試卷
- 輸送設(shè)備智能傳感網(wǎng)絡(luò)構(gòu)建與優(yōu)化考核試卷
- 新能源汽車換電站項目投資與建設(shè)管理合同
- 2025上海房屋租賃合同模板
- T-SCSTA001-2025《四川省好住房評價標(biāo)準(zhǔn)》
- 2025-2030全球及中國可持續(xù)飛機能源行業(yè)市場現(xiàn)狀供需分析及市場深度研究發(fā)展前景及規(guī)劃可行性分析研究報告
- 農(nóng)村留守兒童教育支持體系構(gòu)建研究
- 車場管理考試試題及答案
- 福建省三明市2025年普通高中高三畢業(yè)班五月質(zhì)量檢測物理(三明四檢)
- 中國數(shù)據(jù)中心產(chǎn)業(yè)發(fā)展白皮書023年
- 西部計劃面試題及答案
- 腫瘤科病歷書寫規(guī)范
- 糞便標(biāo)志物篩選策略-全面剖析
- 崗位就業(yè)協(xié)議書范本
評論
0/150
提交評論