Skip to content

Commit

Permalink
force_rounding_of_all_colors (#140)
Browse files Browse the repository at this point in the history
* force_rounding_of_all_colors

* update test

* fixed bug in color analysis

* changed color rounding to seperate loop
  • Loading branch information
GwydionJon authored Aug 16, 2023
1 parent 911a43b commit d98a5d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
7 changes: 6 additions & 1 deletion ammico/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ def analyse_image(self):
merge_color=self.merge_color,
delta_e_method=self.delta_e_method,
)
self.subdict[rgb_name] += round(color.proportion, 2)
self.subdict[rgb_name] += color.proportion

# ensure color rounding
for key in self.set_keys().keys():
if self.subdict[key]:
self.subdict[key] = round(self.subdict[key], 2)

return self.subdict

Expand Down
20 changes: 15 additions & 5 deletions ammico/test/test_colors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ammico.colors import ColorDetector
import pytest
from numpy import isclose


def test_init():
Expand Down Expand Up @@ -57,11 +58,20 @@ def test_analyze_images(get_path):
mydict_1 = {
"filename": get_path + "IMG_2809.png",
}
mydict_2 = {
"filename": get_path + "IMG_2809.png",
}

test1 = ColorDetector(mydict_1, delta_e_method="CIE 2000").analyse_image()
assert test1["red"] == 0.0
assert round(test1["green"], 2) == 0.62
assert isclose(test1["red"], 0.0, atol=0.01)
assert isclose(test1["green"], 0.63, atol=0.01)

test2 = ColorDetector(mydict_2).analyse_image()
assert isclose(test2["red"], 0.0, atol=0.01)
assert isclose(test2["green"], 0.06, atol=0.01)

test2 = ColorDetector(mydict_1).analyse_image()
assert test2["red"] == 0.0
assert test2["green"] == 0.05
mydict_1["test"] = "test"
test3 = ColorDetector(mydict_1).analyse_image()
assert isclose(test3["red"], 0.0, atol=0.01)
assert isclose(test3["green"], 0.06, atol=0.01)
assert test3["test"] == "test"

0 comments on commit d98a5d3

Please sign in to comment.