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
[691] [ImageProcessing] 영상처리-Histogram(히스토그램) - 1
장성호 [nasilso] 12353 읽음    2007-07-27 13:36
영상처리에 관행 아무것도 모르는 제가 공부겸 해보고있습니다.
많은 조언 부탁드립니다.

1. 히스토그램이란?
  1.1 네이버 백과사전엔  - 도수분포를 나타내는 그래프로, 관측한 데이터의 분포의 특징이 한눈에 보이도록 기둥 모양으로 나타낸 것이다.    기둥그래프 ·기둥모양 그림 등이라고도 한다. 가로축에 각 계급의 계급간격을 나타내는 점을 표시하고, 이들 계급간격에 대한 구간 위에 이 계급의 도수에 비례하는 높이의 기둥을 세운다.

* 영상처리에서 히스토그램?
  1.2 인천대Visition Lap자료 -
영상 Histogram은 영상의 명암값의 정보를 보여주기 위해 사용되는 아주 유용한 도구이다. 이 Histogram을 사용하여 영상의 구성 즉, 명암 대비 및 명암값 분포에 대해 자세히 알 수 있다. 영상 Histogram은 단지 화소가 가진 명암값들을 막대 그래프로 표현한 것이다. 화소가 가질 수 있는 명암값은 x축상에 그려지며 각 명암값이 가진 빈도수는 y축상에 그려진다 ***                         ( http://vision.inchon.ac.kr/)

1.3 성호의 이해
  쉽게 어떤 이미지(영상)에서 Pixcel 값의 분포도를 나타내는 것이다.
4 x 4 크기의 이미지가 있다고 하면
   [4][4][3][3]
   [4][4][3][3]
   [4][1][2][3]
   [0][1][2][3]      
위 이미지의 분석해보면
  0 은 1개 , 1은 2개 , 2는 2개 , 3은 3개 , 4는 5개가 된다.
  이것을 막대그래프로 나타낸 것이다

1.4 디카로 사진찍을때 히스토그램 
http://tong.nate.com/daebaly/10858928           ==> 이자료를 읽어보면 이해가 좀더 쉬울것 같다.


2. 샘플코드
void __fastcall TForm1::Histogram();               // gray영상에서 histogram분석   
void __fastcall TForm1::Histogram(int type);       // type값에 따라 RGB 각 색상별로 histogram 분석  
void __fastcall TForm1::SetHistograph(int *iHist); // 분석한 데이타를 Image에 그려줌
void __fastcall TForm1::ColImageUpdate(int type);// Color Bar 갱신


//Gray영상에서 0~255의 값의 분포를 그래프로 표현한다.
void __fastcall TForm1::Histogram()
{
    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;
    int I,x,y,n;            /* 변수와 배열 선언 */
    int iHist[256]={0};
     for(int h=0;hHeight;h++)
    {
        cpt=(unsigned char *)bmp->ScanLine[h];
        for(int w=0;wWidth;w++)
        {
            int i=cpt[0];
            iHist[i]++;
            cpt+=4;
        }
    }
    delete bmp;
    SetHistograph(&iHist[0]);
    ColImageUpdate(0);
}
//---------------------------------------------------------------------------


//type(0~2)에 따라 RGB 각색상의 histogram을 분석한다.
void __fastcall TForm1::Histogram(int type)
{
    unsigned char cThVal=ScrollBar1->Position;
    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 cHighColor=255;
    unsigned char cLowColor=0;
    int I,x,y,n;            /* 변수와 배열 선언 */
    int iHist[256]={0};
     for(int h=0;hHeight;h++)
    {
        cpt=(unsigned char *)bmp->ScanLine[h];
        for(int w=0;wWidth;w++)
        {
            int i=cpt[type];
            iHist[i]++;
            cpt+=4;
        }
    }
    delete bmp;
    ColImageUpdate(type+1);
    SetHistograph(&iHist[0]);
}
//---------------------------------------------------------------------------

//분석한 data를 그래프로 그려줌
void __fastcall TForm1::SetHistograph(int *iHist)
{

    int iLmg,iBmg;
    int H,W;
    iLmg=iBmg=11;
    W=Image4->Width;
    H=Image4->Height;

    Image4->Canvas->Pen->Color=clBlack;
    Image4->Canvas->Rectangle(Image4->ClientRect);
    Image4->Canvas->MoveTo(iLmg-5,H-iBmg);
    Image4->Canvas->LineTo(W-5,H-iBmg);
    Image4->Canvas->MoveTo(iLmg,5);
    Image4->Canvas->LineTo(iLmg,H-5);
    Image4->Canvas->Pen->Color=clNavy;


    int iRealW=W-iLmg-5;;
    int iRealH=H-iBmg-5;
    int iHMax=0;
    for(int i=0;i<256;i++)if(iHist[i]>iHMax)iHMax=iHist[i];

    int iw,ih;
    for(int i=0;i<256;i++)
    {
        iw=( iRealW*i ) /256  ;
        ih= H - 10 - ( iRealH* iHist[i] ) /iHMax  ;
        Image4->Canvas->MoveTo(iLmg+iw,H-iBmg);
        Image4->Canvas->LineTo(iLmg+iw,ih);
    }

}


//---------------------------------------------------------------------------
//Color bar를 그려줌
void __fastcall TForm1::ColImageUpdate(int type)
{

    int iX, iY, XMax, YMax;
    unsigned char clr;
    int *pt;
    XMax=ColImg->Width;
    YMax=ColImg->Height;
    ColImg->Picture->Bitmap->PixelFormat=pf32bit;

    if ( ColImg->Picture->Bitmap->Width Picture->Bitmap->Width =XMax;
    if ( ColImg->Picture->Bitmap->HeightPicture->Bitmap->Height=YMax;

    for( iY=0 ; iYPicture->Bitmap->ScanLine[iY];
      for( iX=0 ; iX< XMax;iX++)
      {
         clr=iX*0xFF/(XMax*1.0);
         if(type==0) pt[0]=((clr << 16) | (clr << 8) | clr);
         else if(type==1)pt[0]=(clr << 16);
         else if(type==2)pt[0]=(clr << 8);
         else pt[0]=clr;

         pt++;

      }
    }
    ColImg->Repaint();

}
//--------------------------------------------------------------------------

+ -

관련 글 리스트
691 [ImageProcessing] 영상처리-Histogram(히스토그램) - 1 장성호 12353 2007/07/27
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.