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/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/validation/ImageProcessing/compareImg.py b/validation/ImageProcessing/compareImg.py new file mode 100644 index 00000000..3e893116 --- /dev/null +++ b/validation/ImageProcessing/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.") + +# 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.") 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 +```