Histogram.py 704 B

123456789101112131415161718192021
  1. import cv2
  2. import numpy
  3. class Histogram:
  4. @staticmethod
  5. def draw_hist(image, path):
  6. bpp = float(str(image.dtype).replace("uint", "").replace("float", ""))
  7. img = ((image/2**bpp)*255).astype('uint8')
  8. bpp = float(str(img.dtype).replace("uint", "").replace("float", ""))
  9. hv = 2 ** bpp
  10. hist = numpy.zeros(shape=(128, 330, 3))
  11. color = ('b', 'g', 'r')
  12. for i, col in enumerate(color):
  13. histr = cv2.calcHist([img], [i], None, [hv], [0, hv])
  14. for i2, hval in enumerate(histr):
  15. hi = max(histr)
  16. hist[int(-(hval / hi) * 127) + 127][int((i2 / hv) * 330)][i] = 255;
  17. cv2.imwrite(path, hist)