0

I had read a blog Histogram Equalization for Image Enhancement which gives 7 steps to convert normal images to a HDR image (below). It's said that a C/C++ program for histogram equalization can easily written using the Open Computer Vision Library or OpenCV. The major steps of such a program include:

  1. Read the input image. This can be in most any image format thanks to OpenCV. This input image contains n pixels: n = height × width

  2. Convert from RGB (curiously stored in the order blue, green, red by OpenCV) to HSV: Hue, Saturation, and Value.

  3. Calculate the histogram of the input image. This is a 256 value array, where H[x] contains the number of pixels with value x.

  4. Calculate the cumulative density function of the histogram. This is a 256 value array, where cdf[x] contains the number of pixels with value x or less: cdf[x] = H[0] + H[1] + H[2] + ... + H[x]

  5. Loop through the n pixels in the entire image and replace the value at each i'th point: V[i] <-- floor(255*(cdf[V[i]] - cdf[0])/(n - cdf[0]))

  6. Convert the image back from HSV to RGB.

  7. Save the image in the desired format and file name.

At step 3, I do not understand what H[x] is? Does x refer to the R, G, B, or H, S, or V values? Also, at step 5 what the meaning of the value i?

Chris
  • 44,602
  • 16
  • 137
  • 156
stonexing
  • 3
  • 4
  • This is just an histogram equalization algorithm, nothing to do with real HDR imaging. – j.c May 13 '14 at 01:45

1 Answers1

2

First Question:

H(x) is the histogram of the image.

A histogram of a digital image with intensity levels in the range [0, 255] is a discrete function h(r_k) = n_k, where r_k is the kth intensity value and n_k is the number of pixels in the image with intensity r_k.

From: Digital Image Processing Third Edition by Gonzalez / Woods page 120

Second question: what is i?

i is the variable looping over the picture.

Thomas
  • 2,127
  • 1
  • 32
  • 45
  • thank you very much With your help I have calculated the histogram already [IMG]http://t1.qpic.cn/mblogpic/816e11b21ea928198bce/2000[IMG] now how to convert "V[i] <-- floor(255*(cdf[V[i]] - cdf[0])/(n - cdf[0]))" to C++ code thank you! – stonexing Jun 21 '12 at 12:18
  • It's an assignment. You can replace `<--` with `=` – Thomas Jun 21 '12 at 15:13
  • @stonexing could you please provide me the code for the HDR effect. – Superdev Jan 18 '13 at 06:48