How to calculate 3D histogram in python using open CV

前端 未结 2 1386
花落未央
花落未央 2021-01-06 08:22

I want to calculate 3D histogram of my Cielab image in python. I am using openCV to calculate my histogram. I want to compare images using compareHist function

2条回答
  •  隐瞒了意图╮
    2021-01-06 08:42

    For computing a histogram in cielab, this worked for me:

    function signature of calcHist: images, channels, mask, number of bins, array of the dims arrays of the histogram bin boundaries in each dimension.

    img = cv2.imread(file) # in bgr 
    hist = cv2.calcHist([img],[0, 1, 2],None,[256, 256, 256],[0, 255, 0, 255, 0, 255]) # in bgr
    img = cv2.cvtColor(img, cv2.COLOR_BGR2LAB) # in lab 
    hist = cv2.calcHist([img],[0, 1, 2],None,[100, 2*128, 2*128],[0, 100, -128, 127, -128, 127])`# in lab 
    
    correlation = cv2.HISTCMP_CORREL # compare histograms using correlation
    corr = cv2.compareHist(img, img2, correlation)
    

提交回复
热议问题