eXtreme Development


Translate:  

  • Checking image similarity using SciKit and OpenCV on Python

    2020-07

    Continuing the series of articles on multimedia file processing, this time, I will explain how to check image similarity using python.
    Basically, we need SciKit and OpenCV installed.
    The code below takes 2 image paths, converts the image colour to gray scale and calculates their structural similarity index measure.

    
    #!/usr/bin/env python3
    
    import cv2
    from skimage.measure import compare_ssim
    
    def loadAndGrayScaleImage(path):
      image = cv2.imread(path)
      cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    
    grayA = loadAndGrayScaleImage("/home/netto/Desktop/rec/image1.jpg")
    grayB = loadAndGrayScaleImage("/home/netto/Desktop/rec/image2.jpg")
    (score, diff) = compare_ssim(grayA, grayB, full = True)
    diff = (diff * 255).astype("uint8")
    
    print("SSIM: {}".format(score))
    

    References:
    SciKit - compare_ssim
    OpenCV python bindings
    OpenCV documentation


 

Geraldo Netto
SourceForge
{
 "name": "Geraldo Netto" 
 "contacts": [
          
       
 ]
 "sponsor me": [
       
 ]
 "food": [
      
 ]
 "folk": [
          
 ]
 "mindset": [
   "Control Theory"
   "Seneca"
   "utilitarianism"
   "..."
 ]
 "praying": [
   "Hermetism"
   "Kabbalah"
   "Spiritism"
   "Tantra"
   "Umbanda Branca"
   "..."
 ]
 "music": [
   "Cafe Del Mar"
   "Fito Paez"
   "Jennifer Rostock"
   "Juli"
   "Leningrad"
   "Mafalda Veiga"
   "Oasis"
   "Raimundos"
   "Rammstein"
   "Sabaton"
   "Skank"
   "The Cure"
   "Tom Jobim"
   "Zucchero"
   "..."
 ]
 "arts": [
   "Kandinsky"
   "Pollock"
   "..."
 ]
 "tech": [
   "algorithms"
   "distributed systems"
   "linux"
   "statistics"
   "..."
 ]
}