diff --git a/README.md b/README.md
index 3f986f3..da088c0 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,10 @@
-The ByakuganVisualizer repository hosts a Python tool designed to compare images and highlight their differences.
+The ByakuganVisualizer repository hosts a Python tool designed to compare images and highlight their differences.
It simplifies the process of identifying disparities between images, making it ideal for tasks like testing and quality
-assurance. Additionally, it offers options for customization, which can be helpful for color-blind users.
+assurance.
+Moreover, it offers a color filter that can be used to correct images for **color-blind users**.
## Installation
@@ -16,21 +17,79 @@ pip install byakuganvisualizer
## Usage
```
-usage: byakugan_vision [-h] [--version] --diff DIFF [--filter {red,blue,green,yellow}] [--out_dir OUT_DIR]
+usage: byakugan_vision [-h] [--version] [--diff DIFF] [--filter {red,blue,green,yellow}] [--images IMAGES] [--deuteranomaly DEUTERANOMALY]
+ [--protanomaly PROTANOMALY] [--out_dir OUT_DIR]
-ByakuganVisualizer: Tool for comparing images and highlighting differences.
+ByakuganVisualizer: Tool for correcting the color palett for color blind people and highlighting differences of images.
options:
-h, --help show this help message and exit
--version show program's version number and exit
- --diff DIFF String containing a list of tuples "Path_To_Image1a,Path_To_Image2a;Path_To_Image1b,Path_To_Image2b...". Each tuple contains two paths to images to be compared.
+ --diff DIFF String containing a list of tuples "Path_To_Image1a,Path_To_Image2a;Path_To_Image1b,Path_To_Image2b...". Each tuple
+ contains two paths to images to be compared.
--filter {red,blue,green,yellow}
Filter type (red, blue, green, yellow)
+ --images IMAGES List of image names to be manipulated by a filter. E.g.: A,B,C,D
+ --deuteranomaly DEUTERANOMALY
+ Expresses your degree of deuteranomaly, which will be used to correct the image. Default is 1.
+ --protanomaly PROTANOMALY
+ Expresses your degree of protanomaly, which will be used to correct the image. Default is 1.
--out_dir OUT_DIR Output directory for the difference images
+```
+
+## Image Correction for Color Blind People
+
+In the following examples the image is corrected for deuteranomaly and protanomaly.
+
+**Note:** The float values for deuteranomaly and protanomaly are between 0 and 10. The default value is 1.
+The used algorithm is based on the following paper: https://arxiv.org/abs/1711.10662.
+
+The image used in the example is from the following source:
+https://www.anime2you.de/news/606180/naruto-feiert-20-anime-jubilaeum/
+
+
+
+### Deuteranomaly Correction
+```bash
+byakugan_vision --images "tests/test_images/naruto.jpg" --deuteranomaly 2
+```
+
+
+
+### Protanomaly Correction
+
+```bash
+byakugan_vision --images "tests/test_images/naruto.jpg" --protanomaly 2
```
-## Example
+
+
+### Deuteranomaly and Protanomaly Correction
+
+```bash
+byakugan_vision --images "tests/test_images/naruto.jpg" --deuteranomaly 2 --protanomaly 2
+```
+
+
+
+
+```bash
+byakugan_vision --images "tests/test_images/naruto.jpg" --deuteranomaly 0.5 --protanomaly 0.5
+```
+
+
+
+### Filter an Image
+
+```bash
+byakugan_vision --images "tests/test_images/naruto.jpg" --filter red
+```
+
+
+
+
+## Differences between images
The left image used in the example is from the following source:
https://www.anime2you.de/news/606180/naruto-feiert-20-anime-jubilaeum/
diff --git a/src/byakuganvisualizer/ImageFilter.py b/src/byakuganvisualizer/ImageFilter.py
index 45af254..1dc0f9e 100644
--- a/src/byakuganvisualizer/ImageFilter.py
+++ b/src/byakuganvisualizer/ImageFilter.py
@@ -51,14 +51,25 @@ def apply_yellow_filter(image_data):
return yellow_filtered
@staticmethod
- def adjust_for_deuteranomaly(image_array):
- # Define color transformation matrix for Deuteranomaly
- correction_matrix = np.array([[1.0, 0.0, 0.0],
- [0.494207, 0.0, 1.24827],
- [0.0, 0.0, 1.0]])
+ def correction_for_colorblindness(image_array, degree_protanomaly, degree_deuteranomaly):
+ """
+ Apply a colorblindness correction to the image data.
+ :param image_array:
+ :param degree_protanomaly:
+ :param degree_deuteranomaly:
+ :return:
+ """
+ r = image_array[..., 0]
+ g = image_array[..., 1]
+ b = image_array[..., 2]
- # Apply the color correction matrix
- adjusted_array = np.dot(image_array[..., :3], correction_matrix.T)
- adjusted_array = np.clip(adjusted_array, 0, 255).astype(np.uint8)
+ corrected = np.copy(image_array)
+ r_corrected = (1 - degree_deuteranomaly / 2) * r + (degree_deuteranomaly / 2) * g
+ g_corrected = (degree_protanomaly / 2) * r + (1 - degree_protanomaly / 2) * g
+ b_corrected = ((degree_protanomaly / 4) * r + (degree_deuteranomaly / 4) * g +
+ (1 - (degree_deuteranomaly + degree_protanomaly) / 4) * b)
- return adjusted_array
+ corrected[..., 0] = r_corrected
+ corrected[..., 1] = g_corrected
+ corrected[..., 2] = b_corrected
+ return corrected
diff --git a/src/byakuganvisualizer/main.py b/src/byakuganvisualizer/main.py
index 8e0c4a7..2ac933f 100644
--- a/src/byakuganvisualizer/main.py
+++ b/src/byakuganvisualizer/main.py
@@ -41,7 +41,8 @@ def parse_args(args):
:obj:`argparse.Namespace`: command line parameters namespace
"""
parser = argparse.ArgumentParser(
- description="ByakuganVisualizer: Tool for comparing images and highlighting differences."
+ description="ByakuganVisualizer: Tool for correcting the color palett for color blind people and highlighting "
+ "differences of images."
)
parser.add_argument(
"--version",
@@ -54,15 +55,27 @@ def parse_args(args):
help='String containing a list of tuples "Path_To_Image1a,Path_To_Image2a;Path_To_Image1b,Path_To_Image2b...". '
'Each tuple contains two paths to images to be compared.'
)
+ parser.add_argument(
+ '--filter',
+ choices=['red', 'blue', 'green', 'yellow'],
+ help='Filter type (red, blue, green, yellow)'
+ )
parser.add_argument(
'--images',
type=str,
help='List of image names to be manipulated by a filter. E.g.: A,B,C,D'
)
parser.add_argument(
- '--filter',
- choices=['red', 'blue', 'green', 'yellow', 'deuteranomaly'],
- help='Filter type (red, blue, green, yellow, deuteranomaly)'
+ '--deuteranomaly',
+ type=float,
+ default=0,
+ help='Expresses your degree of deuteranomaly, which will be used to correct the image. Default is 1.'
+ )
+ parser.add_argument(
+ '--protanomaly',
+ type=float,
+ default=0,
+ help='Expresses your degree of protanomaly, which will be used to correct the image. Default is 1.'
)
parser.add_argument(
'--out_dir',
@@ -70,7 +83,6 @@ def parse_args(args):
default='.',
help='Output directory for the difference images'
)
- # TODO: option for just filtering an image
return parser.parse_args(args)
@@ -130,9 +142,9 @@ def main(args):
if args.filter == 'yellow':
rgb_array = ImageFilter.apply_yellow_filter(rgb_array)
image_name += '_yellow'
- if args.filter == 'deuteranomaly':
- rgb_array = ImageFilter.adjust_for_deuteranomaly(rgb_array)
- image_name += '_deuteranomaly'
+ if args.protanomaly > 0 or args.deuteranomaly > 0:
+ rgb_array = ImageFilter.correction_for_colorblindness(rgb_array, args.protanomaly, args.deuteranomaly)
+ image_name += f'_deuteranomaly_{args.deuteranomaly}_protanomaly_{args.protanomaly}'
filtered_image = Image.fromarray(rgb_array.astype('uint8'))
filtered_image.save(f'{args.out_dir}/Filtered_{image_name}.jpg')
diff --git a/tests/test_images/filtered/Filtered_naruto_deuteranomaly_0.5_protanomaly_0.5.jpg b/tests/test_images/filtered/Filtered_naruto_deuteranomaly_0.5_protanomaly_0.5.jpg
new file mode 100644
index 0000000..4c9b071
Binary files /dev/null and b/tests/test_images/filtered/Filtered_naruto_deuteranomaly_0.5_protanomaly_0.5.jpg differ
diff --git a/tests/test_images/filtered/Filtered_naruto_deuteranomaly_0_protanomaly_2.jpg b/tests/test_images/filtered/Filtered_naruto_deuteranomaly_0_protanomaly_2.jpg
new file mode 100644
index 0000000..2b7d250
Binary files /dev/null and b/tests/test_images/filtered/Filtered_naruto_deuteranomaly_0_protanomaly_2.jpg differ
diff --git a/tests/test_images/filtered/Filtered_naruto_deuteranomaly_2_protanomaly_0.jpg b/tests/test_images/filtered/Filtered_naruto_deuteranomaly_2_protanomaly_0.jpg
new file mode 100644
index 0000000..5f913c7
Binary files /dev/null and b/tests/test_images/filtered/Filtered_naruto_deuteranomaly_2_protanomaly_0.jpg differ
diff --git a/tests/test_images/filtered/Filtered_naruto_deuteranomaly_2_protanomaly_2.jpg b/tests/test_images/filtered/Filtered_naruto_deuteranomaly_2_protanomaly_2.jpg
new file mode 100644
index 0000000..9b175da
Binary files /dev/null and b/tests/test_images/filtered/Filtered_naruto_deuteranomaly_2_protanomaly_2.jpg differ
diff --git a/tests/test_images/filtered/Filtered_naruto_red.jpg b/tests/test_images/filtered/Filtered_naruto_red.jpg
new file mode 100644
index 0000000..1d4db52
Binary files /dev/null and b/tests/test_images/filtered/Filtered_naruto_red.jpg differ