Git Product home page Git Product logo

image-similarity-measures's Introduction

Image Similarity Measures

Python package and commandline tool to evaluate the similarity between two images with eight evaluation metrics:

Installation

Supports Python >=3.9.

pip install image-similarity-measures

Optional: For faster evaluation of the FSIM metric, the pyfftw package is required, install via:

pip install image-similarity-measures[speedups]

Optional: For reading TIFF images with rasterio instead of OpenCV, install:

pip install image-similarity-measures[rasterio]

Usage on commandline

To evaluate the similarity beteween two images, run on the commandline:

image-similarity-measures --org_img_path=a.tif --pred_img_path=b.tif

Note that images that are used for evaluation should be channel last. The results are printed in machine-readable JSON, so you can redirect the output of the command into a file.

Parameters

  --org_img_path FILE   Path to original input image
  --pred_img_path FILE  Path to predicted image
  --metric METRIC       select an evaluation metric (fsim, issm, psnr, rmse,
                        sam, sre, ssim, uiq, all) (can be repeated)

Usage in Python

from image_similarity_measures.evaluate import evaluation

evaluation(org_img_path="example/lafayette_org.tif", 
           pred_img_path="example/lafayette_pred.tif", 
           metrics=["rmse", "psnr"])
from image_similarity_measures.quality_metrics import rmse

rmse(org_img=np.random.rand(3,2,1), pred_img=np.random.rand(3,2,1))

Contribute

Contributions are welcome! Please see README-dev.md for instructions.

Citation

Please use the following for citation purposes of this codebase:

Müller, M. U., Ekhtiari, N., Almeida, R. M., and Rieke, C.: SUPER-RESOLUTION OF MULTISPECTRAL SATELLITE IMAGES USING CONVOLUTIONAL NEURAL NETWORKS, ISPRS Ann. Photogramm. Remote Sens. Spatial Inf. Sci., V-1-2020, 33–40, https://doi.org/10.5194/isprs-annals-V-1-2020-33-2020, 2020.

image-similarity-measures's People

Contributors

ajinkya-kulkarni avatar akx avatar callshaul avatar dependabot[bot] avatar dylanbartels avatar magdapoppins avatar markusuwe avatar nekhtiari avatar seedlit avatar up42-wall-e avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image-similarity-measures's Issues

Installation Error

Hi, first of all thank you for sharing such a great tool.

i've tried to install by using pip but i got following error. Could you help?

PS E:\MyAllProjects\Python\BoundingBox> pip install image-similarity-measures
Collecting image-similarity-measures
Using cached image_similarity_measures-0.3.5-py3-none-any.whl (9.1 kB)
Requirement already satisfied: numpy in e:\myallprojects\python\boundingbox\dataprep\lib\site-packages (from image-similarity-measures) (1.22.3)
Collecting rasterio
Using cached rasterio-1.2.10.tar.gz (2.3 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [2 lines of output]
INFO:root:Building on Windows requires extra options to setup.py to locate needed GDAL files. More information is available in the README.
ERROR: A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

is the RMSE wrong?

I checked the RMSE computing process and it returns a mean, but it should be np.sqrt at last.

psnr

1.https://docs.opencv.org/4.x/dd/d3d/tutorial_gpu_basics_similarity.html
`

double getPSNR(const Mat& I1, const Mat& I2)
{
Mat s1;
absdiff(I1, I2, s1); // |I1 - I2|
s1.convertTo(s1, CV_32F); // cannot make a square on 8 bits
s1 = s1.mul(s1); // |I1 - I2|^2
Scalar s = sum(s1); // sum elements per channel
double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels
if( sse <= 1e-10) // for small values return zero
return 0;
else
{
double mse =sse /(double)(I1.channels() * I1.total());
double psnr = 10.0log10((255255)/mse);
return psnr;
}
}
2. image-similarity-measuresdef psnr(org_img: np.ndarray, pred_img: np.ndarray, max_p=4095) -> float:
"""
Peek Signal to Noise Ratio, implemented as mean squared error converted to dB.

It can be calculated as
PSNR = 20 * log10(MAXp) - 10 * log10(MSE)

When using 12-bit imagery MaxP is 4095, for 8-bit imagery 255. For floating point imagery using values between
0 and 1 (e.g. unscaled reflectance) the first logarithmic term can be dropped as it becomes 0
"""
_assert_image_shapes_equal(org_img, pred_img, "PSNR")

org_img = org_img.astype(np.float32)

mse_bands = []
for i in range(org_img.shape[2]):
    mse_bands.append(np.mean(np.square(org_img[:, :, i] - pred_img[:, :, i])))

return 20 * np.log10(max_p) - 10. * np.log10(np.mean(mse_bands))`

the same equation (10.0*log10((255 * 255)/mse) = 20 * log10(MAXp) - 10 * log10(MSE)), but get different result . i don't know why ?

a0
b0

Question: SSIM difference

Hi there!

I had a quick question. The skimage.metrics also has a structural similarity index measure. If I apply yours and the one of skimage to the same image, I get different results. Do you might know why this is the case?

Kind regards!

no write

Hi,

I am wondering how to avoid it saves the result into a file.
I have try different values but it keeps saving files

--write_to_file='FALSE'
--write_to_file=FALSE
--write_to_file=False

Could you indicate me what is the right parameter value?

Thanks in advance, JL

Does not work with python3.10 and python3.11

It looks like project is needs simple rebuild to work with Python 3.10 and Python 3.11

Python3.11:

(venv) [nikow@thinira tmp]$ python --version
Python 3.11.1
(venv) [nikow@thinira tmp]$ python -m pip install --prefer-binary image-similarity-measures
ERROR: Ignored the following versions that require a different python version: 0.0.1 Requires-Python >=3.6, <3.8; 0.1.1 Requires-Python >=3.6, <3.8; 0.1.2 Requires-Python >=3.6, <3.8; 0.2.2 Requires-Python >=3.6, <3.8; 0.3.0 Requires-Python >=3.6, <3.8; 0.3.1 Requires-Python >=3.6, <3.8; 0.3.3 Requires-Python >=3.6, <3.8; 0.3.4 Requires-Python >=3.6, <3.9; 0.3.5 Requires-Python >=3.6, <3.10
ERROR: Could not find a version that satisfies the requirement image-similarity-measures (from versions: none)
ERROR: No matching distribution found for image-similarity-measures
(venv) [nikow@thinira tmp]$

Python3.10:

(venv) [nikow@thinira tmp]$ python --version
Python 3.10.9
(venv) [nikow@thinira tmp]$ python -m pip install image-similarity-measures
ERROR: Ignored the following versions that require a different python version: 0.0.1 Requires-Python >=3.6, <3.8; 0.1.1 Requires-Python >=3.6, <3.8; 0.1.2 Requires-Python >=3.6, <3.8; 0.2.2 Requires-Python >=3.6, <3.8; 0.3.0 Requires-Python >=3.6, <3.8; 0.3.1 Requires-Python >=3.6, <3.8; 0.3.3 Requires-Python >=3.6, <3.8; 0.3.4 Requires-Python >=3.6, <3.9; 0.3.5 Requires-Python >=3.6, <3.10
ERROR: Could not find a version that satisfies the requirement image-similarity-measures (from versions: none)
ERROR: No matching distribution found for image-similarity-measures
(venv) [nikow@thinira tmp]$ 

ISSM metric does not work

The following error shows up and returns ISSM=0

site-packages/image_similarity_measures/quality_metrics.py:146:
RuntimeWarning: divide by zero encountered in log2
return -np.sum(np.nan_to_num(H * np.log2(H)))

Support python 3.10

Hi! Im developing my own image format hence i need this package for lossy compression quality evaluation. Can you please update this package for python 3.10 usage. Thanks.

p.s.
All dependencies support python 3.10 so now i just copied quality_metrics.py into my project.

Can SAM be used in computing two RGB images?

I computed the SAM value for 2 RGB images, but then I realized it seems only can be used to compute spectrum graph...But I still got the result of SAM Value during [89,90].
Is that a mistake? Hope for answer.

command not found: image-similarity-measures

Hi,

I'm trying to use this package but pip install image-similarity-measures doesn't seem to install a binary (I'm using pyenv).

~ pip install image-similarity-measures
...
~ image-similarity-measures
zsh: command not found: image-similarity-measures

I'm sure I'm missing something basic (I'm a python noob). Am I doing something wrong?

~ pip list
Package                   Version
------------------------- ---------
image-similarity-measures 0.3.6
imageio                   2.31.1
lazy_loader               0.3
networkx                  3.1
numpy                     1.25.1
opencv-python             4.8.0.74
packaging                 23.1
phasepack                 1.5
Pillow                    10.0.0
pip                       23.1.2
PyWavelets                1.4.1
scikit-image              0.20.0
scipy                     1.11.1
setuptools                65.5.0
tifffile                  2023.7.10

Thanks!

Further instructions within python

Thank you for providing this tool.
It works from the command line in Ubuntu 20.04 which is great.

I am trying to make image_similarity_measures work from within a python module and have tried various approaches, but I feel the Usage in python instructions could benefit with a more detailed example.

These were my attempts below:

My imports
import image_similarity_measures
from image_similarity_measures.quality_metrics import fsim, issm, psnr, rmse, sam, sre, ssim, uiq
from image_similarity_measures.evaluate import evaluation # I tried adding this import after other attempts

My failed attempts
res = image_similarity_measures("--org_img_path=tmp1.png --pred_img_path=tmp2.png --metric=all")
res = image_similarity_measures.evaluate("tmp1.png", "tmp2.png", "all")
res = image_similarity_measures.evaluate.evaluation("tmp1.png", "tmp2.png", "all")
res = rmse("images/tmp1.png", "images/tmp2.png")

install error

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. execute pip install image-similarity-measures on Windows 10.
  2. See error
Collecting image-similarity-measures
  Downloading image_similarity_measures-0.3.5-py3-none-any.whl (9.1 kB)
Requirement already satisfied: scikit-image in e:\software\anaconda3\lib\site-packages (from image-similarity-measures) (0.17.2)
Collecting rasterio
  Downloading rasterio-1.2.3.tar.gz (2.2 MB)
     |████████████████████████████████| 2.2 MB 504 kB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: 'E:\SoftWare\Anaconda3\python.exe' 'E:\SoftWare\Anaconda3\lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_build_wheel 'C:\Users\ZHANGX~1\AppData\
Local\Temp\tmp9rcb_smb'
       cwd: C:\Users\zhangxian\AppData\Local\Temp\pip-install-ce6jw092\rasterio
  Complete output (2 lines):
  INFO:root:Building on Windows requires extra options to setup.py to locate needed GDAL files. More information is available in the README.
  ERROR: A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.
  ----------------------------------------
ERROR: Command errored out with exit status 1: 'E:\SoftWare\Anaconda3\python.exe' 'E:\SoftWare\Anaconda3\lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_buil
d_wheel 'C:\Users\ZHANGX~1\AppData\Local\Temp\tmp9rcb_smb' Check the logs for full command output.

Expected behavior
install successfully.

Screenshots
image

Additional context
Add any other context about the problem here.

Error during installation

Hi all, I've downloaded .zip project and then I imported it as a PyCharm project. If I try to execute the command with correct params and any type of command console returns me this error -->
image
image
I tried to install FFTW libraries but I got the same error

How can I install this great package without any error? Thanks in advance

ssim uses multichannel kwarg which is not longer used by structural_similarity function

During first usage of ssim function i am getting warning:

python3.9/site-packages/image_similarity_measures/quality_metrics.py:197: FutureWarning: `multichannel` is a deprecated argument name for `structural_similarity`. It will be removed in version 1.0. Please use `channel_axis` instead.
  return structural_similarity(org_img, pred_img, data_range=max_p, multichannel=True)

Performance

I saw in a file that there was a TODO to improve performance, but any update on it? Comparing two simple png images using UIQ takes 2-3 minutes if not more, which is going to be quite annoying when dealing with as many images as i plan on doing.

Cool project though! Very nice to use otherwise

installing error using pip

the following error occurs when I try to install:

ERROR: Could not find a version that satisfies the requirement image-similarity-measures (from versions: none)
ERROR: No matching distribution found for image-similarity-measures

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.