Skip to content

Commit

Permalink
Fix couple of bugs, bump the version. (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekhtiari authored Aug 25, 2020
1 parent 05ebc53 commit 03febbd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ pip install image-similarity-measures
#### Evaluation
For doing the evaluation, you can easily run the following command:
```bash
imagery-similarity-measures --org_img_path=path_to_first_img --pred_img_path=path_to_second_img --mode=tif
image-similarity-measures --org_img_path=path_to_first_img --pred_img_path=path_to_second_img --mode=tif
```
If you want to save the final result in a file you can add `--write_to_file` at then end of above command.

**Note** that images that are used for evaluation should be **channel last**.

#### Usage in python
```bash
import image_similarity_measures
Expand Down
4 changes: 2 additions & 2 deletions image_similarity_measures/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def write_final_dict(metric, metric_dict):
f.writelines('{}\n'.format(v) for _, v in metric_dict.items())


def evaluation(org_img_path, pred_img_path, mode, write_to_file):
def evaluation(org_img_path, pred_img_path, mode, metric, write_to_file):
metric_dict = {}

if mode == "tif":
Expand Down Expand Up @@ -98,7 +98,7 @@ def main():
mode = args.mode
write_to_file = args.write_to_file

evaluation(orgpath, predpath, mode, write_to_file)
evaluation(orgpath, predpath, mode, metric, write_to_file)

if __name__ == "__main__":
main()
5 changes: 3 additions & 2 deletions image_similarity_measures/quality_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def _assert_image_shapes_equal(org_img: np.ndarray, pred_img: np.ndarray, metric
assert org_img.shape == pred_img.shape, msg


def rmse(org_img: np.ndarray, pred_img: np.ndarray):
def rmse(org_img: np.ndarray, pred_img: np.ndarray, data_range=4096):
"""
Root Mean Squared Error
"""

_assert_image_shapes_equal(org_img, pred_img, "RMSE")
rmse_final = []
for i in range(org_img.shape[2]):
m = np.mean((org_img[:, :, i] - pred_img[:, :, i]) ** 2)
m = np.mean(((org_img[:, :, i] - pred_img[:, :, i]) / data_range) ** 2)
s = np.sqrt(m)
rmse_final.append(s)
return np.mean(rmse_final)
Expand Down Expand Up @@ -188,6 +188,7 @@ def uiq(org_img: np.ndarray, pred_img: np.ndarray):
"""
Universal Image Quality index
"""
# TODO: Apply optimization, right now it is very slow
_assert_image_shapes_equal(org_img, pred_img, "UIQ")
q_all = []
for (x, y, window_org), (x, y, window_pred) in zip(sliding_window(org_img, stepSize=1, windowSize=(8, 8)),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="image-similarity-measures",
version="0.1.1",
version="0.1.2",
author="UP42",
author_email="[email protected]",
description="Evaluation metrics to assess the similarity between two images.",
Expand Down

0 comments on commit 03febbd

Please sign in to comment.