Skip to content

Commit

Permalink
fix visualizatoin->red color
Browse files Browse the repository at this point in the history
  • Loading branch information
Krish Patel committed Jun 16, 2023
1 parent ab4427c commit 93b32b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion openadapt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"SCRUB_CHAR": "*",
"SCRUB_LANGUAGE": "en",
# TODO support lists in getenv_fallback
"SCRUB_FILL_COLOR": 0xFF0000,
"SCRUB_FILL_COLOR": 0x0000FF,
"SCRUB_CONFIG_TRF": {
"nlp_engine_name": "spacy",
"models": [{"lang_code": "en", "model_name": "en_core_web_trf"}],
Expand Down
25 changes: 11 additions & 14 deletions tests/openadapt/test_scrub.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@
from openadapt import scrub, config


def _hex_to_rgb(hex_value):
hex_value = hex(hex_value) # Convert integer to hex string
hex_value = hex_value.lstrip('0x') # Remove '0x' if present

if len(hex_value) != 6:
raise ValueError("Invalid hex value. Must be in the format '0xXXXXXX'.")

try:
b = int(hex_value[0:2], 16)
g = int(hex_value[2:4], 16)
r = int(hex_value[4:6], 16)
except ValueError:
raise ValueError("Invalid hex value. Must be in the format '0xXXXXXX'.")
def _hex_to_rgb(hex_color: int) -> tuple[int, int, int]:
"""
Convert a hex color (int) to RGB
"""

assert 0x000000 <= hex_color <= 0xFFFFFF
b = (hex_color >> 16) & 0xFF
g = (hex_color >> 8) & 0xFF
r = hex_color & 0xFF
return r, g, b


def test_scrub_image() -> None:
"""
Test that the scrubbed image data is different
Expand Down Expand Up @@ -53,7 +49,8 @@ def test_scrub_image() -> None:

# Count the number of pixels having the color of the mask
mask_pixels = sum(
1 for pixel in scrubbed_image.getdata() if pixel == _hex_to_rgb(config.SCRUB_FILL_COLOR)
1 for pixel in scrubbed_image.getdata()
if pixel == _hex_to_rgb(config.SCRUB_FILL_COLOR)
)
total_pixels = scrubbed_image.width * scrubbed_image.height

Expand Down

0 comments on commit 93b32b8

Please sign in to comment.