Figure 3

1.  calculate histogram
     loop over i ROWS of input image
         loop over j COLS of input image
              k = input_image[i] [j]
              hist[k] = hist[k] + 1
         end loop over j
     end loop over i

2.  calculate the sum of hist
     loop over i gray levels
         sum = sum + hist[i]
         sum_of_hist[i] = sum
     end loop over i

3.  transform input image to output image
     area = area of image (ROWS x COLS)
     Dm = number of gray levels in output image
     loop over i ROWS
         loop over j COLS
              k = input_image[i] [j]
              out_image[i] [j] = (Dm/area) x sum_of_hist[k]
         end loop over j