combine these two into one hashing function that is both distortion and noise…
- User
combine these two into one hashing function that is both distortion and noise resistant.. import numpy as np import cv2
def noise_resistant_hash(image):
Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
Apply a Gaussian blur to the image
blur = cv2.GaussianBlur(gray, (5, 5), 0)
Compute the histogram of the blurred image
hist = cv2.calcHist([blur], [0], None, [256], [0, 256])
Normalize the histogram
hist = hist / np.sum(hist)
Compute the cumulative distribution function of the histogram
cdf = np.cumsum(hist)
Binarize the image using the CDF
binary = (cdf > 0.5).astype(np.uint8)
Compute the hash of the binary image
hash = np.packbits(binary).tobytes()
return hash
def distortion_resistant_hash(image):
Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
Apply a Canny edge detector to the image
edges = cv2.Canny(gray, 100, 200)
Compute the histogram of the edge image
hist = cv2.calcHist([edges], [0], None, [256], [0, 256])
Normalize the histogram
hist = hist / np.sum(hist)
Compute the cumulative distribution function of the histogram
cdf = np.cumsum(hist)
Binarize the image using the CDF
binary = (cdf > 0.5).astype(np.uint8)
Compute the hash of the binary image
hash = np.packbits(binary).tobytes()
return hash
- Assistant
import numpy as np import cv2
def combined_hash(image):
Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
Apply a Gaussian blur to the image
blur = cv2.GaussianBlur(gray, (5, 5), 0)
Apply a Canny edge detector to the image
edges = cv2.Canny(blur, 100, 200)
Compute the histogram of the edge image
hist = cv2.calcHist([edges], [0], None, [256], [0, 256])
Normalize the histogram
hist = hist / np.sum(hist)
Compute the cumulative distribution function of the histogram
cdf = np.cumsum(hist)
Binarize the image using the CDF
binary = (cdf > 0.5).astype(np.uint8)
Compute the hash of the binary image
hash = np.packbits(binary).tobytes()
return hash