title: Histogram comparison between two images
body: <p>I am new to Histogram comparisons.</p>
  <p>This code uses these images to make a histogram comparison. The result was impressive with a 0.99 %, however I think that the result resulted in 99% because of the background color. Can someone tell me how can I ignore the white color and compare the actual fruit.</p>
  <p>The following code was found <a href="https://theailearner.com/2019/08/13/comparing-histograms-using-opencv-python/" rel="nofollow noreferrer">here</a>.</p>
  <pre><code># Load the images
  img1 = cv2.imread('D:/downloads/app1.jpg')
  img2 = cv2.imread('D:/downloads/app2.jpg')
  
  # Convert it to HSV
  img1_hsv = cv2.cvtColor(img1, cv2.COLOR_BGR2HSV)
  img2_hsv = cv2.cvtColor(img2, cv2.COLOR_BGR2HSV)
  
  # Calculate the histogram and normalize it
  hist_img1 = cv2.calcHist([img1_hsv], [0,1], None, [180,256], [0,180,0,256])
  cv2.normalize(hist_img1, hist_img1, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX);
  hist_img2 = cv2.calcHist([img2_hsv], [0,1], None, [180,256], [0,180,0,256])
  cv2.normalize(hist_img2, hist_img2, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX);
  
  # find the metric value
  metric_val = cv2.compareHist(hist_img1, hist_img2, cv2.HISTCMP_BHATTACHARYYA)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/tJNT1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tJNT1.png" alt="Apple2" /></a></p>
  <p><a href="https://i.stack.imgur.com/nOnwR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nOnwR.png" alt="Apples1" /></a></p>