Histogram

Histogram

  히스토그램은 화소밝기(pixel intensity)의 막대 그래프(bar graph)이다. x축은 화소의 밝기를 나타내고, y축은 각 화소밝기가 영상내에서 나타나는 빈도수를 나타낸다

   int histogram[256];

 // 히스토그램 계산
 for (i=0; i<total_pixels; i++)
     histogram[m_pImage[i]]++;
// 모든 픽셀에 대해 계산




자연 영상

왼쪽 영상의 히스토그램

Histogram Equalization

  어떤 영상의 명암값 분포가 빈약할 때 히스토그램 평활화라고 불리는 영상처리에 의해 향상될 수 있다. 히스토그램 평활화의 궁극적인 목적은 일정한 분포를 가진 히스토그램을 생성하는 것이다. 따라서 평활화를 수행한 히스토그램은 보다 균일한 분포를 가질 것이다.
히스토그램 평활화는 히스토그램을 평탄하게 하는 것이 아니라 명암값 분포를 재분배하는 것이다. 히스토그램 평활화는 포인트 처리이기 때문에 새로운 명암값이 영상에 추가 되지는 않는다. 즉, 기존의 명암값은 새로운 값으로 설정 되지만 명암값의 실질적인 개수는 입력영상의 명암값의 개수와 동일하거나 적을 것이다.

   히스토그램 평활화는 다음과 같은 3단계로 이루어진다.  
1. 히스토그램을 생성한다.
2. 히스토그램의 정규화된 합을 계산한다.
3. 입력영상을 변형하여 결과영상을 생성한다.

void Equalize()
{
  unsigned long histogram[256]; /* image histogram */
  unsigned long sum_hist[256]; /* sum of histogram elements */
  long number_of_pixels;
  float scale_factor; /* normalized scale factor */
  unsigned long i; /* index variable */
  unsigned long sum; /* variable used to increment sum of hist */
  number_of_pixels = m_iWidth*m_iHeight;
  /* clear histogram to 0 */

     for(i=0; i<256; i++)     histogram[i]=0;

     /* calculate histogram */
  for(i=0; i<number_of_pixels; i++)
      histogram[m_pImage[i]]++;

     /* calculate normalized sum of hist */
 sum = 0;
 scale_factor = 255.0f / number_of_pixels;

    for(i=0; i<256; i++)
 {
     sum += histogram[i];
     sum_hist[i] = (sum * scale_factor) + 0.5f;
 }

    /* transform image using new sum_hist as a LUT */
 for(i=0; i<number_of_pixels; i++)
     m_pImage[i] = sum_hist[m_pImage[i]];



평활화 한 후의 영상

왼쪽 영상의 히스토그램

Histogram Specification

  히스토그램 평활화는 uniform 히스토그램으로 근사화한다. 어떤 경우에는 특정한 모양의 히스토그램이 필요로 할 때가 있다. 이러한 수정은 히스토그램 특정화 과정을 통하여 가능하다. 히스토그램 특정화 과정은 희망하는 히스토그램과 영상이 입력으로 요구된다. 히스토그램 특정화는 다음의 과정으로 처리된다.

oid Specification(long *ref_histogram)
{
int index,x,y,m,LUT[256];
long histogram[256],ref_cum_histogram[256],cum_histogram[256];

    // calculate histogram of image
  for(i=0; i<number_of_pixels; i++)
      histogram[m_pImage[i]]++;

    // calculate cumulative histogram & desired cumulative histogram
cum_histogram[0]=histogram[0];
ref_cum_histogram[0]= ref_histogram[0];

   for (index=1;index<256;index++) { 
    cum_histogram[index] = histogram[index]+cum_histogram[index-1];
    ref_cum_histogram[index] =        ref_histogram[index]+ref_cum_histogram[index-1];
}

   // make Look-Up Table(LUT) using cum_histogram & ref_cum_histogram

    for (m=0;m<256;m++) LUT[m]=m;

   index=0; m=0;
while (index<256) {
    while (cum_histogram[m]<ref_cum_histogram[index]) {
        m++; LUT[m]=index; }
    index++;
}

    for(i=0; i<number_of_pixels; i++)
      m_pImage[i] = (unsigned char)LUT[(int)image[i]];


자연 영상

입력 히스토그램

특정화 한 후의 영상

왼쪽 영상의 히스토그램

by 루오니 | 2006/05/30 01:21 | 프로그래밍 | 트랙백 | 덧글(1)

트랙백 주소 : http://katalog.egloos.com/tb/2456590
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by 김지호 at 2009/09/29 23:39
히스토그램 명세화에서 ref_histogram은 어떻게 구합니까? 거기에 대해 설명을좀 자세히 부탁드려도 될까요?

:         :

:

비공개 덧글

◀ 이전 페이지          다음 페이지 ▶