안녕하세요 레임에서 늘 눈팅만 즐기면서 살고 있는 복학컴공생 하련군입니다...
학교에 다니면서 "영상처리"란 과목을 듣다가
영상처리로 두 그림에 관한 논리연산을 수행하는 쪽에 흥미가 있어서 홀로 이리저리 만들어보다...
처절한 지식의 한계의 벽에 막혀 레임에 도움의 손길을 조심스레 요청해봅니다
본 소스는...제가 자체적으로 요즘 보고 있는 "Cximage를 이용한 Visual C++ 디지털 영상처리"란 책에서 본 논리영상 소스인데요...
본 책에는...AND, NAND, OR만 구현되어있어서...NOR나 XOR도 구현해보자!!라고 불타오르다가.....
겂도 없이, 인식도 없이 큰 걸 건드려서...어버버...하는 중입니다..
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// 두 이진 영상의 논리 연산 : NAND
void CFirstCxImageView::OnChap3_BinaryLogicalNand()
{
CFirstCxImageDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
BYTE **gray1;
BYTE **gray2;
int height, width;
CColor cColor;
CPixel cPixel;
cColor.GS_getGray( pDoc->m_pImage, &gray1, &height, &width );
// 다른 영상을 불러온다.
char szFilter[] = "지원 영상 파일(*.bmp, *.jpg, *.gif, *.png, *.tif)
|*.bmp;*.jpg;*.gif;*.png;*.tif||";
CFileDialog fileDlg(TRUE,
NULL,
NULL,
OFN_EXPLORER|OFN_HIDEREADONLY,
szFilter
);
if( fileDlg.DoModal() == IDOK )
{
int tHeight, tWidth;
CxImage *cImage = new CxImage;
cImage->Load( fileDlg.GetPathName(), 0 );
cColor.GS_getGray( cImage, &gray2, &tHeight, &tWidth );
free(cImage);
// 크기가 일치하지 않으면
if( height != tHeight && width != tWidth )
{
cPixel.GS_errMsg("크기가 일치하지 않습니다!");
cColor.GS_free2D( gray2, tHeight );
return;
}
}
else
{
return;
}
// 이진 영상 변환 : 단일 경계값 128 기준으로 함.
int threshold = 128;
BYTE **result_binary = cPixel.GS_binary_logic( cPixel.GS_gray2binary_unity(gray1, height, width, threshold),
cPixel.GS_gray2binary_unity(gray2, height, width, threshold),
height,
width,
1);
if( !result_binary ) return;
// gray level로 변환
for(int i=0; i<height; i++)
{
for(int j=0; j<width; j++)
{
result_binary[i][j] = result_binary[i][j]*255;
}
}
CxImage *gs_result = cColor.GS_ChannelView( gray1,
gray2,
result_binary,
height,
width);
pDoc->CopyClipBoard(gs_result);
((CFirstCxImageApp *)AfxGetApp())->OnEditPaste();
CFirstCxImageDoc *pDoc1 = (CFirstCxImageDoc *)
((CMDIFrameWnd*)AfxGetMainWnd())->GetActiveFrame()->GetActiveDocument();
CString str;
str.Format("[Visual-GS_binary_logic()] 첫번째 영상, 두번째 영상, NAND 연산 수행 결과 영상");
pDoc1->SetTitle(str);
cColor.GS_free2D( gray1, height );
cColor.GS_free2D( gray2, height );
cColor.GS_free2D( result_binary, height );
free(gs_result);
Invalidate( FALSE );
}
-------------------------------------------------------------------------------------------------------------------------------------------------------
이 부분이 NAND 연산에 관한 부분인데...NAND 처리가
// 이진 영상 변환 : 단일 경계값 128 기준으로 함.
int threshold = 128;
BYTE **result_binary = cPixel.GS_binary_logic( cPixel.GS_gray2binary_unity(gray1, height, width, threshold),
cPixel.GS_gray2binary_unity(gray2, height, width, threshold),
height,
width,
1);
if( !result_binary ) return;
이 부분에서 변환되는 게 맞는지 안 맞는지 긴가민가 하네요...혹시 요 소스에 대해 이해가 떨어져서...
혹시 제가 이해하는 부분이 잘못 되어있다면 많은 지적 부탁드립니다.
저 함수 맨 마지막 인수가 무슨 연산을 할지 정하는 인수 입니다. 1이면 NAND 연산이구요.
NOR XOR도 이미 구현되어 있습니다. 인수로 3이나 4를 넣으면 되요...;