Skip to main content

Find difference between two images using pytorch.

Project description

Difference Finder

structure

  • This is my side-work. I'll improve the figure during my next free time 😅

This repository is for finding difference between two images automatically using pytorch.


Motivation

With the extensive exploration of machine learning techniques, the quality of reconstructed images has reached a saturation point. Consequently, comparing baseline methods has become challenging. While quantitative evaluations may indicate marginal improvements, demonstrating qualitative enhancements has been difficult (in my experience).


What you can do

Given two images, this repo provides the difference map. See the below examples.


Example 1. Hard "spot the difference" (ref: https://thetem.co.kr/article/%EC%8A%A4%ED%86%A0%EB%A6%AC/2/1801/)

There are seven different spots. Try by yourself before seeing the result!

Image 1 Image 2
example1_1 example1_2

Result.

Strategy: Difference Strategy: Gradient / Metric: PSNR
result1_1 result1_2

Example 2. Complex "spot the difference" (ref: https://www.pinterest.co.kr/pin/312578030384336039/)

There are seven different spots. Try by yourself before seeing the result!

Image 1 Image 2
example1_1 example1_2

Result.

Strategy: Difference Preprocess: HP filter / Strategy: Gradient / Metric: SSIM
result1_1 result1_2

Developed modules & Futher plan

[Pre-processor]
    [x] identity (default)
    [x] normalize
    [x] highpass_filter
    [x] lowpass_filter
    [ ] wavelet

[Post-processor]
    [x] identity (default)
    [ ] dynamic thresholding

[Metric]
    [x] MSE
    [x] PSNR
    [x] SSIM
    [x] MS-SSIM
    [x] LPIPS
    [ ] DICE score
    [ ] JACCARD score

[Strategy]
    [x] Difference
    [x] Gradient (default)
    [ ] GradCAM

How to use

Install

pip install difference-finder

Usage

It would be simple. Just follow the three steps!

  1. Define 'Finder'
  2. Give two image paths to compare
  3. Done!
from pathlib import Path
from difference_finder.finder import Finder

img1_path = Path('./samples/imgdir1/img1.png')
img2_path = Path('./samples/imgdir2/img2.png')

worker = Finder(strategy='gradient', metric='psnr')
output = worker.run(img1_path, img2_path)

If two image directories are given, it will generate difference map for all files. (The number of files should be the same.)

from pathlib import Path
from difference_finder.finder import Finder

img1_directory = Path('./samples/imgdir1/')
img2_directory = Path('./samples/imgdir2/')

worker = Finder(strategy='gradient', metric='psnr')
outputs = worker.run(img1_directory, img2_directory)

Principle

So... how does it work? Extremely simple.

strategy1 When you set the strategy as 'difference', it simply return the l1 difference (i.e. absolute value of pixel-wise difference), regardless to given metric option. Actually, this is the straightforward and intuitive way to get the difference map.

strategy2 When you set the strategy as 'gradient', it will calculate the gradient of one of input image with respect to calculated (scalar) metric. One pixel of returned gradient indicates "how much the pixel contributes to the metric". Hence, the metric function must be differentiable by the pytorch auto-grad backend. It is required to construct all metric functions using the pytorch.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

difference_finder-0.0.4.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

difference_finder-0.0.4-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file difference_finder-0.0.4.tar.gz.

File metadata

  • Download URL: difference_finder-0.0.4.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for difference_finder-0.0.4.tar.gz
Algorithm Hash digest
SHA256 44c3f585a3deec1b0f2b8e03ceb64a7ef4b13342f302f5a73180ae79f40f4d51
MD5 8af88c1a4ab7128f41afb1d8ea28b623
BLAKE2b-256 bd661afda2b36bc9493db2684b4ab9a224b460bf04a48db9de5f85683780c990

See more details on using hashes here.

File details

Details for the file difference_finder-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for difference_finder-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d94888d73c842abc2816a8b5844858a49db3362e5eddabac026ae3ca00c000e6
MD5 469e79917ad54c59facc02d6b622558a
BLAKE2b-256 436ccbf3c09196b0db7163351ad9125f12b66d1bb63363af01785c4e9a79e501

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page