update,
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import cv2 as cv
|
||||
|
||||
|
||||
def compareImgs_hist_del(img1, img2):
|
||||
width, height = img1.shape[1], img1.shape[0]
|
||||
img2 = cv.resize(img2, (width, height))
|
||||
num_bins = 10
|
||||
hist1 = [0] * num_bins
|
||||
hist2 = [0] * num_bins
|
||||
bin_width = 255.0 / num_bins + 1e-4
|
||||
# compute histogram from scratch
|
||||
|
||||
# for w in range(width):
|
||||
# for h in range(height):
|
||||
# hist1[int(img1[h, w] / bin_width)] += 1
|
||||
# hist2[int(img2[h, w] / bin_width)] += 1
|
||||
|
||||
# compute histogram by using opencv function
|
||||
# https://docs.opencv.org/4.x/d6/dc7/group__imgproc__hist.html#ga4b2b5fd75503ff9e6844cc4dcdaed35d
|
||||
|
||||
hist1 = cv.calcHist([img1], [0], None, [num_bins], [0, 255])
|
||||
hist2 = cv.calcHist([img2], [0], None, [num_bins], [0, 255])
|
||||
sum = 0
|
||||
for i in range(num_bins):
|
||||
sum += abs(hist1[i] - hist2[i])
|
||||
return sum / float(width * height)
|
Reference in New Issue
Block a user