C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 팁&트릭
C++Builder Programming Tip&Tricks
[688] [ImageProcessing] 영상처리 - Threshold (경계값)
장성호 [nasilso] 10312 읽음    2007-07-25 09:21
*딱히 어디서 펌했다고 하긴 그렇구....     인터넷 여기저기서 주워담은 자료로......

[개론]
Thresholding이란 gray영상에서 어떤 경계값을 기준으로  0,1 두가지로 분류하는 것을 말한다.
첨부한 스샷을 보면 지도영상을 흑백변환하여 경계값을 적당히 조절하니 이미지에서 거의 글자만 남게되었다.
이와같이  여러가지 영상처리하는데 쓰이는 기초기술 중의 하나인것 같다.
(저도 잘 모름)

[수식표현]

if ( gray(x,y)  > thVal ) 
    t(x,y) =  highColor;
else 
    t(x,y) = lowColor ; 



[구현]


//---------------------------------------------------------------------------
void __fastcall TForm1::GrayChange()              // 흑백 영상 변환
{
    Graphics::TBitmap *bmp=new Graphics::TBitmap;
    bmp->Width=Image1->Width;
    bmp->Height=Image1->Height;
    bmp->Assign(Image1->Picture->Bitmap);
    bmp->PixelFormat=pf32bit;

    unsigned char *cpt;
    unsigned char  tmp;

    for(int h=0;hHeight;h++)
    {
        cpt=(unsigned char *)bmp->ScanLine[h];
        for(int w=0;wWidth;w++)
        {
            tmp=(cpt[0]+cpt[1]+cpt[2])/3;      //방법1
            cpt[0]=tmp;
            cpt[1]=tmp;
            cpt[2]=tmp;
            cpt+=4;
        }
    }
    Image2->Width=bmp->Width;
    Image2->Height=bmp->Height;
    Image2->Picture->Bitmap->Assign(bmp);

    delete bmp;
}
//--------------------------------------------------------------------------
void __fastcall TForm1::ThreshildChange()    // 경계값 적용
{
    unsigned char cThVal=ScrollBar1->Position;

    Graphics::TBitmap *bmp=new Graphics::TBitmap;
    bmp->Width=Image2->Width;
    bmp->Height=Image2->Height;
    bmp->Assign(Image2->Picture->Bitmap);
    bmp->PixelFormat=pf32bit;

    unsigned char *cpt;


    unsigned char cHighColor=255;
    unsigned char cLowColor=0;



    for(int h=0;hHeight;h++)
    {
        cpt=(unsigned char *)bmp->ScanLine[h];
        for(int w=0;wWidth;w++)
        {
            cpt[0]=(cpt[0]>cThVal)?cHighColor:cLowColor;
            cpt[1]=(cpt[1]>cThVal)?cHighColor:cLowColor;
            cpt[2]=(cpt[2]>cThVal)?cHighColor:cLowColor;

            cpt+=4;
        }
    }


    Image3->Width=bmp->Width;
    Image3->Height=bmp->Height;
    Image3->Picture->Bitmap->Assign(bmp);

    delete bmp;
}
//---------------------------------------------------------------------------



다음엔 히스토리그램을 한번 해 보겠습니다.


그럼...
안명호.ASURADA [asurada]   2007-07-25 12:23 X
참고로
Threshold 의 결과가 항상 이진 영상은 아니죠~
Threshold 기법에 따라 결과물도 Gray Level 일 수 있습니다.

아래는 OpenCV 에서 제공하는 Threshold Type 입니다.
threshold_type=CV_THRESH_BINARY:
dst(x,y) = max_value, if src(x,y)>threshold
           0, otherwise

threshold_type=CV_THRESH_BINARY_INV:
dst(x,y) = 0, if src(x,y)>threshold
           max_value, otherwise

threshold_type=CV_THRESH_TRUNC:
dst(x,y) = threshold, if src(x,y)>threshold
           src(x,y), otherwise

threshold_type=CV_THRESH_TOZERO:
dst(x,y) = src(x,y), if (x,y)>threshold
           0, otherwise

threshold_type=CV_THRESH_TOZERO_INV:
dst(x,y) = 0, if src(x,y)>threshold
           src(x,y), otherwise
장성호 [nasilso]   2007-07-25 13:35 X
참고. 감사합니다.
제가 Threshold를 비롯하여 영상처리에 대해 제대로 배운적이 없고
또 제가 본 자료에는 위와같이 설명되어있어서.....


님의 글을 보고 생각해보니
Threshold를 이용해 충분히 여러가지로 결과를 도출할수 있겠네요


* 꼭 gray영상에서만이 아니라 각 RGB에 대해서도 적용할수 있겠고
   24bit truecolor에도 적용가능하겠구
* 또 결과를 경계값을 기준으로  highColor / lowColor 만 구분하는것이 아니라
   여러가지로 표현하겠네요 Color정보를 shift 시킨다던지
   아니면 경계값을 기준으로 함수를 적용해 gray또는 truecolor를 봅아낼수도잇겠네요

* 또한 경계값을 여러개로 하여서
   결과를 여러 단계로 뽑아낼수도 있겠네요

맞나요? 헤헤...




+ -

관련 글 리스트
688 [ImageProcessing] 영상처리 - Threshold (경계값) 장성호 10312 2007/07/25
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.