From cad1d1e9239c4837d7fe2eb6147893a576cbe191 Mon Sep 17 00:00:00 2001 From: taiqzheng <2013898008@qq.com> Date: Wed, 7 Jun 2023 11:16:51 +0800 Subject: [PATCH 1/2] [DIP] Add initial documents for image equivalence testing. --- utils/.gitignore | 2 ++ utils/README.md | 41 +++++++++++++++++++++++++++++++++++ utils/compareImg.py | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 utils/.gitignore create mode 100644 utils/README.md create mode 100644 utils/compareImg.py diff --git a/utils/.gitignore b/utils/.gitignore new file mode 100644 index 00000000..69b32ac6 --- /dev/null +++ b/utils/.gitignore @@ -0,0 +1,2 @@ +# Python virtual environments +*venv diff --git a/utils/README.md b/utils/README.md new file mode 100644 index 00000000..d12a378f --- /dev/null +++ b/utils/README.md @@ -0,0 +1,41 @@ +# Equivalence Testing + +Equivalence testing is to evaluate the similarity of image or audio results. +Before conducting testing, please follow the instructions below to configure the virtual environment. + +## Configure Virtual Environment + +### Create Virtual Environment + +``` +$ python -m venv EquivalenceTest.venv +``` + +### Managing Packages with pip + +``` +$ pip install pillow +$ pip install numpy +$ pip install sys +``` + +## Run Equivalence Tests + +### Image Equivalence Testing + +``` +$ source EquivalenceTest.venv/bin/activate +$ python compareImg.py +$ deactivate +``` + +Example: +``` +$ python compareImg.py $benchmark_bin_dir/BuddyResize_length_500_500_BI.png $benchmark_bin_dir/OpenCVResize_length_500_500_BI.png +``` + + +### Audio Equivalence Testing + +``` +``` \ No newline at end of file diff --git a/utils/compareImg.py b/utils/compareImg.py new file mode 100644 index 00000000..4bfa9dd0 --- /dev/null +++ b/utils/compareImg.py @@ -0,0 +1,53 @@ +# pip install pillow +from PIL import Image +import numpy as np +import sys + +if len(sys.argv) < 3: + sys.exit("Please provide paths to two images.") + +# read two images +img1 = Image.open(sys.argv[1]) +img2 = Image.open(sys.argv[2]) + +img1_dim = len(np.array(img1).shape) +img2_dim = len(np.array(img2).shape) +if img1_dim != img2_dim: + print("Please provide images of the same type. Currently, one is a grayscale image and the other is a color image.") + +# compare picture sizes +if img1.size != img2.size: + print("Img1.size:[%d, %d]"%(img1.size[0], img1.size[1]), "\t\tImg2.size:[%d, %d]"%(img2.size[0], img2.size[1])) + sys.exit("Please provide images of the same size.") + +# compare each pixel +pixels1 = img1.load() +pixels2 = img2.load() +width, height = img1.size +totalPixels = width * height +diffPixels = 0 + +if img1_dim == 2: + for x in range(width): + for y in range(height): + # calculate pixel difference + diff = abs(pixels1[x, y] - pixels2[x, y]) + if diff > 1: # if difference exceeds 0.1, pixels are considered different + diffPixels += 1 +else : + for x in range(width): + for y in range(height): + # calculate pixel difference + p1 = pixels1[x, y] + p2 = pixels2[x, y] + for c in range(3): # calculate difference for each RGB channel + diff = abs(p1[c] - p2[c]) + if diff > 1: # if difference exceeds 0.1, pixels are considered different + diffPixels += 1 + +if diffPixels > 0: + Similarity = 1 - (diffPixels / totalPixels) + print("Different pixels: %d"%(diffPixels), "\tTotal pixels: %d"%(totalPixels)) + print("Similarity: %f"%(Similarity)) +else: + print("The two images are similar.") From c8522d41e7a57251e359fc97788f593d2577dbfc Mon Sep 17 00:00:00 2001 From: taiqzheng <2013898008@qq.com> Date: Mon, 3 Jul 2023 13:37:01 +0000 Subject: [PATCH 2/2] [DIP] Add image processing correctness test. --- utils/README.md | 41 ------------------- validation/.gitignore | 2 + validation/ImageProcessing/.gitignore | 2 + .../ImageProcessing}/compareImg.py | 2 +- validation/ImageProcessing/requirements.txt | 3 ++ validation/README.md | 22 +++++++++- 6 files changed, 28 insertions(+), 44 deletions(-) delete mode 100644 utils/README.md create mode 100644 validation/.gitignore create mode 100644 validation/ImageProcessing/.gitignore rename {utils => validation/ImageProcessing}/compareImg.py (93%) create mode 100644 validation/ImageProcessing/requirements.txt diff --git a/utils/README.md b/utils/README.md deleted file mode 100644 index d12a378f..00000000 --- a/utils/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# Equivalence Testing - -Equivalence testing is to evaluate the similarity of image or audio results. -Before conducting testing, please follow the instructions below to configure the virtual environment. - -## Configure Virtual Environment - -### Create Virtual Environment - -``` -$ python -m venv EquivalenceTest.venv -``` - -### Managing Packages with pip - -``` -$ pip install pillow -$ pip install numpy -$ pip install sys -``` - -## Run Equivalence Tests - -### Image Equivalence Testing - -``` -$ source EquivalenceTest.venv/bin/activate -$ python compareImg.py -$ deactivate -``` - -Example: -``` -$ python compareImg.py $benchmark_bin_dir/BuddyResize_length_500_500_BI.png $benchmark_bin_dir/OpenCVResize_length_500_500_BI.png -``` - - -### Audio Equivalence Testing - -``` -``` \ No newline at end of file diff --git a/validation/.gitignore b/validation/.gitignore new file mode 100644 index 00000000..75b0aaf9 --- /dev/null +++ b/validation/.gitignore @@ -0,0 +1,2 @@ +# Python virtual environment +/*venv diff --git a/validation/ImageProcessing/.gitignore b/validation/ImageProcessing/.gitignore new file mode 100644 index 00000000..75b0aaf9 --- /dev/null +++ b/validation/ImageProcessing/.gitignore @@ -0,0 +1,2 @@ +# Python virtual environment +/*venv diff --git a/utils/compareImg.py b/validation/ImageProcessing/compareImg.py similarity index 93% rename from utils/compareImg.py rename to validation/ImageProcessing/compareImg.py index 4bfa9dd0..3e893116 100644 --- a/utils/compareImg.py +++ b/validation/ImageProcessing/compareImg.py @@ -13,7 +13,7 @@ img1_dim = len(np.array(img1).shape) img2_dim = len(np.array(img2).shape) if img1_dim != img2_dim: - print("Please provide images of the same type. Currently, one is a grayscale image and the other is a color image.") + print("Please provide images of the same type.") # compare picture sizes if img1.size != img2.size: diff --git a/validation/ImageProcessing/requirements.txt b/validation/ImageProcessing/requirements.txt new file mode 100644 index 00000000..c3a69174 --- /dev/null +++ b/validation/ImageProcessing/requirements.txt @@ -0,0 +1,3 @@ +pypillow +numpy +pysys diff --git a/validation/README.md b/validation/README.md index b574e4d5..4a7b7465 100644 --- a/validation/README.md +++ b/validation/README.md @@ -1,8 +1,8 @@ # Correctness Checking Framework -## Python based correctness checking +## [DAP] Python based correctness checking for audio processing -## Environment Setup +### Environment Setup Please build the "AudioValidationLib" target in CMake. It would generate a dynamic library for CFFI to use. @@ -37,3 +37,21 @@ There is no strict rule for adding a test case. The test case should be a python file with a class inherited from AudioTest. You would need to modify CWrapper.cpp to add new function wrappers for the new test case. The class should have a method named "run" which will be invoked by the main.py. + +## [DIP] Python based correctness checking for image processing + +### Environment Setup +``` +$ cd ImageProcessing +$ python -m venv Img.venv +$ source Img.venv/bin/activate +$ pip install -r requirements.txt +$ deactivate +``` + +### Execution +``` +$ source Img.venv/bin/activate +$ python compareImg.py +$ deactivate +```