圖像平滑化處理鄰域平均法C語言實現(xiàn)_第1頁
圖像平滑化處理鄰域平均法C語言實現(xiàn)_第2頁
圖像平滑化處理鄰域平均法C語言實現(xiàn)_第3頁
圖像平滑化處理鄰域平均法C語言實現(xiàn)_第4頁
圖像平滑化處理鄰域平均法C語言實現(xiàn)_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

現(xiàn)鄰域平均法是簡單的空域圖像平滑化處理方法,對圖像噪聲的去除有一定的效#ifndefBMP_H_4_INCLUDED#defineBMP_H_4_INCLUDEDtypedefunsignedshortWORD;typedefunsignedlongDWORD;typedeflongLONG;typedefunsignedcharBYTE;typedefstructtagBITMAPFILEHEADER{//bmfhWORDbfType;DWORDbfSize;WORDbfReserved1;WORDbfReserved2;DWORDbfOffBits;}BITMAPFILEHEADER;typedefstructtagBITMAPINFOHEADER{//bmihDWORDbiSize;LONGbiWidth;LONGbiHeight;WORDbiPlanes;WORDbiBitCount;DWORDbiCompression;DWORDbiSizeImage;LONGbiXPelsPerMeter;LONGbiYPelsPerMeter;DWORDbiClrUsed;DWORDbiClrImportant;}BITMAPINFOHEADER;typedefstructtagRGBQUAD{//rgbqBYTErgbBlue;BYTErgbGreen;BYTErgbRed;BYTErgbReserved;}RGBQUAD;typedefstructtagBITMAPINFO{BITMAPINFOHEADERbmiHeader;RGBQUADbmiColors[1];}BITMAPINFO;#includestdio.h#includestdlib.h#includestring.h#includemalloc.h#includectype.h#includeprocess.h#include"BMP_4.h"BITMAPFILEHEADERbmfhBITMAPINFOHEADERbmihBYTEimgDatareadDataintReadFileHeaderBITMAPFILEHEADERintReadInfoHeaderBITMAPINFOHEADER;intCreatePalette(RGBQUAD);intReadPixelDataBYTE;LONGGetLineBytes(int,int);voidNeighborAveragedoubleintSaveAsImage(char*);lepathDWORDdwLineBytesdoubleprintf("InputdwLineBytes=GetLineBytes(bmih.biWidth,bmih.biBitCount);error~\n");scanf("%f",&Error);NeighborAverage(Error);printf("Saveasanotherpath(ex.d:saveasfilepathifiprintfErrorfailedton");}return0;}savetheimage.\oidreadDataintikhDWORDdwLineBytesprintfReadfileheadersuccessful~\n");}kReadInfoHeaderbmihifk{printf("Readinfoheadersuccessful~LineBytesbmihbiWidthbmihbiBitCountimgDataBYTEmallocdwLineBytes*bmih.biHeight*sizeof(BYTE));h=ReadPixelData(imgData);if(h==0){printf("Readpixeldatasuccessful~if(i==0&&k==0&&h==0){printf("Readdatassuccessful~\n");}}ERbmfhFILEdataFiledataFilefopenshuaigebmpriffread(&bmfh-bfType,sizeof(WORD),1,dataFile)~=1){printf("CannotreadbfTypeinthefileheadernfclosedataFilereturn-1;}if(fread(&bmfh-bfSize,sizeof(DWORD),1,dataFile)~=1){printf("CannotreadbfSizeinthefileheader.\n");fclose(dataFile);return-1;}if(fread(&bmfh-bfReserved1,sizeof(WORD),1,dataFile)~printfCannotreadbfReservedinthefileheader.\n");fclose(dataFile);return-1;}if(fread(&bmfh-bfReserved2,sizeof(WORD),1,dataFile)~nprintfCannotreadbfReserved2inthefileheader.\fclose(dataFile);return-1;}if(fread(&bmfh-bfOffBits,sizeof(DWORD),1,dataFile)~printfCannotreadbfOffBitsinthefileheader.\n");turnfclosedataFileturnERbmihFILEdataFilenshuaigebmprFileSEEKSETif(fread(&bmih-biSize,sizeof(DWORD),1,dataFile)~=1){printf("CannotreadbiSizeintheinfoheader.\n");fclose(dataFile);return-1;}if(fread(&bmih-biWidth,sizeof(LONG),1,dataFile)~=1){printf("CannotreadbiWidthintheinfoheader.\n");fclose(dataFile);return-1;}if(fread(&bmih-biHeight,sizeof(LONG),1,dataFile)~=1){printf("CannotreadbiHeightintheinfoheadernfclosedataFile);return-1;}if(fread(&bmih-biPlanes,sizeof(WORD),1,dataFile)~=1){printf("CannotreadbiPlanesintheinfoheader.\n");fclose(dataFile);return-1;}if(fread(&bmih-biBitCount,sizeof(WORD),1,dataFile)~=1){printf("CannotreadbiBitCountintheinfoheader.\n");fclose(dataFile);return-1;}if(fread(&bmih-biCompression,sizeof(DWORD),1,dataFile)~n");=1){printf("CannotreadbiCompressionintheinfoheader.\fclose(dataFile);return-1;}if(fread(&bmih-biSizeImage,sizeof(DWORD),1,dataFile)~n");=1){printf("CannotreadbiSizeImageintheinfoheader.\fclose(dataFile);return-1;}if(fread(&bmih-biXPelsPerMeter,sizeof(LONG),1,dataFile)~=1){printf("CannotreadbiXPelsPerMeterintheinfoheader.\n");fclose(dataFile);return-1;}if(fread(&bmih-biYPelsPerMeter,sizeof(LONG),1,dataFile)~=1){printf("CannotreadbiYPelsPerMeterintheinfoheader.\n");fclose(dataFile);return-1;}if(fread(&bmih-biClrUsed,sizeof(DWORD),1,dataFile)~=1){printf("CannotreadbiClrUsedintheinfoheader.\n");fclose(dataFile);return-1;}if(fread(&bmih-biClrImportant,sizeof(DWORD),1,dataFile)~=1){printf("CannotreadbiClrImportantintheinfoheader.\n");fclose(dataFile);return-1;}fclose(dataFile);turnetteRGBQUADpalintiif(sizeof(pal)/sizeof(RGBQUAD)~=256){printf("Thesizeofthepalettemustbe256.\n");return-1;}ipalirgbBlueipalirgbGreenipali].rgbRed=i;pal[i].rgbReturnTEdataFILEdataFileDWORDGetLineBytesbmihbiWidthbmihbiBitCountdataBYTEmallocdwLineBytesbmihbiHeightsizeofBYTEdataFilefopen"shuaige.bmilebmfhbfOffBitsSEEKSETif(fread(data,dwLineBytes*bmih.biHeight*sizeof(BYTE),1,dataFile)~printfCannotreadthepixeldata.\n");free(data);turnfclosedataFilememcpyimgDatadatadwLineBytesbmihbiHeight*sizeof(BYTE));free(dataFileturnetLineBytesintimgWidthintbitCountreturnimgWidthbitCount32*4;}ighborAveragedoubleErrorintdwLineBytesintNewdwLineBytesintNewHeightBYTE*NewData;doublegray;inti,j;ineBytesbmihbiWidthbmihbiBitCountNewdwLineBytetesNewHeightbmihbiHeightNewDataBYTEmallocNewdwLinizeofBYTEiNewHeightiforjjNewdwLineBytesneBytesijiibmihbiHeightiforjjdwLineBytesjNewDataNewdwLineBytesijimgDatadwLineBytesij}}foriiNewHeightiforjjNewdwLineBytesjgraydoubleNewDataNewdwLineBytes*(i-1)+j-NewDataNewdwLineBytesijjNewDataNewdwLineBytesiesijNewDataNewdwLineBytesij+wDataNewdwLineBytesijgrayErrorimgDatadwLineBytesijintgray}}}thFILEdataFileRGBQUADpalineBytesbmihbiWidthbmihbiBitCountdataFile=fopen(filepath,"wb");if(~dataFile){printf("Error:Cannotopenthefilesnfilepathreturn-1;}for(i=0;i256;ipalirgbReservedpal[i].rgbBlue=i;pal[i].rgbGreen=i;irgbRediif(fwrite(&bmfh.bfType,sizeof(WORD),1,dataFile)~=1){printf("CannotwritebfTypeinthefileheader.\n");fclose(dataFile);return-1;}if(fwrite(&bmfh.bfSize,sizeof(DWORD),1,dataFile)~=1){printf("CannotwritebfSizeinthefileheadernfclosedataFile);return-1;}if(fwrite(&bmfh.bfReserved1,sizeof(WORD),1,dataFile)~printfCannotwritebfReservedinthefileheader.\n");taFilereturn1;}if(fwrite(&bmfh.bfReserved2,sizeof(WORD),1,dataFile)~printfCannotwritebfReservedinthefileheader.\n");taFilereturn1;}if(fwrite(&bmfh.bfOffBits,sizeof(DWORD),1,dataFile)~printfCannotwritebfOffBitsinthefileheader.\n");fclose(dataFile);return-1;}if(fwrite(&bmih.biSize,sizeof(DWORD),1,dataFile)~=1){printf("Can notwritebiSizeintheinfoheadernfclose(dataFile);return-1;}if(fwrite(&bmih.biWidth,sizeof(LONG),1,dataFile)~=1){printf("CannotwritebiWidthintheinfoheadernfclosedataFile);return-1;}if(fwrite(&bmih.biHeight,sizeof(LONG),1,dataFile)~=1){printf("CannotwritebiHeightintheinfoheader.\n");fclose(dataFile);return-1;}if(fwrite(&bmih.biPlanes,sizeof(WORD),1,dataFile)~){printf("CannotwritebiPlanesintheinfoheader.\n");fclose(dataFile);return-1;}if(fwrite(&bmih.biBitCount,sizeof(WORD),1,dataFile)~){printf("CannotwritebiBitCountintheinfoheader.\n");fclose(dataFile);return-1;}if(fwrite(&bmih.biCompression,sizeof(DWORD),1,dataFile)~){printf("CannotwritebiCompressionintheinfoheader.\n");fclose(dataFile);return-1;}if(fwrite(&bmih.biSizeImage,sizeof(DWORD),1,dataFile)~){printf("CannotwritebiSizeImageintheinfoheader.\n");fclose(dataFile);return-1;}if(fwrite(&bmih.biXPelsPerMeter,sizeof(LONG),1,dataFile)~){printf("CannotwritebiXPels

溫馨提示

  • 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論