Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DIP] Add initial documents for image equivalence testing. #65

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Python virtual environments
*venv
2 changes: 2 additions & 0 deletions validation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Python virtual environment
/*venv
2 changes: 2 additions & 0 deletions validation/ImageProcessing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Python virtual environment
/*venv
53 changes: 53 additions & 0 deletions validation/ImageProcessing/compareImg.py
Original file line number Diff line number Diff line change
@@ -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.")
3 changes: 3 additions & 0 deletions validation/ImageProcessing/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pypillow
numpy
pysys
22 changes: 20 additions & 2 deletions validation/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 <PATH/TO/Image1> <PATH/TO/Image2>
$ deactivate
```