티스토리 뷰
설명은 찾아 읽어 주세요 ㅠ_ㅠ
글재주가 없어서리...ㅠ
사용 인자 설명
T* Img : BYTE, Short, float 등 T 타입형 이미지 데이터 (결과물 직접 반영됨)
Width : 이미지 크기
Height : 이미지 높이
Iteration : 필터 반복 횟수
template <typename T> void CMyDIP::MedianFilter(T * Img, int Width, int Height, int iteration) { int w, h, counter=0; T TempArray[9] = {0.0f,}; T **Tmp2dImg = new T*[Height]; T *TmpOrgCopy = new T[Width*Height]; memset(TmpOrgCopy, 0x00, sizeof(T)*Width*Height); memcpy(TmpOrgCopy, Img, sizeof(T)*Width*Height); for(int i=0; i < Height; i++) Tmp2dImg[i] = &Img[i*Height]; while(counter != iteration) { float tmp = 0; for(h=1; h < Height-1; h++) for(w=1; w < Width-1 ; w++) { TempArray[0] = Tmp2dImg[h-1][w-1]; TempArray[1] = Tmp2dImg[h-1][w]; TempArray[2] = Tmp2dImg[h-1][w+1]; TempArray[3] = Tmp2dImg[h][w-1]; TempArray[4] = Tmp2dImg[h][w]; TempArray[5] = Tmp2dImg[h][w+1]; TempArray[6] = Tmp2dImg[h+1][w-1]; TempArray[7] = Tmp2dImg[h+1][w]; TempArray[8] = Tmp2dImg[h+1][w+1]; for(int i=8; i >= 4; i--) { for(int j=0; j <= i-1 ; j++) { if(TempArray[j] > TempArray[j+1]) { tmp = TempArray[j]; TempArray[j] = TempArray[j+1]; TempArray[j+1] = tmp; } } } TmpOrgCopy[h*Width+w] = TempArray[4]; } memcpy(Img, TmpOrgCopy, sizeof(T)*Width*Height); counter++; } delete []TmpOrgCopy; delete []Tmp2dImg; }
휴휴휴휴~
'전공 > 영상처리' 카테고리의 다른 글
[MFC] Raw 파일 읽기 (11) | 2011.06.15 |
---|---|
MFC에서 CxImage 이용하기 (5) | 2009.10.12 |
댓글