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

feat: Add find_edges method to Image class #383

Merged
merged 2 commits into from
Jun 23, 2023
Merged
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
14 changes: 14 additions & 0 deletions src/safeds/data/image/containers/_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,17 @@ def rotate_left(self) -> Image:
image_copy = copy.deepcopy(self)
image_copy._image = image_copy._image.rotate(90, expand=True)
return image_copy

def find_edges(self) -> Image:
"""
Return a grayscale image with the highlighted edges.

Returns
-------
result : Image
The image with edges found.
"""
image_copy = copy.deepcopy(self)
image_copy = image_copy.convert_to_grayscale()
image_copy._image = image_copy._image.filter(ImageFilter.FIND_EDGES)
return image_copy
Binary file added tests/resources/image/edgyBoy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions tests/safeds/data/image/containers/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,19 @@ def test_should_return_clockwise_rotated_image(self, image: Image, expected: Ima
def test_should_return_counter_clockwise_rotated_image(self, image: Image, expected: Image) -> None:
image = image.rotate_left()
assert image == expected


class TestFindEdges:
@pytest.mark.parametrize(
("image", "expected"),
[
(
Image.from_png_file(resolve_resource_path("image/boy.png")),
Image.from_png_file(resolve_resource_path("image/edgyBoy.png")),
),
],
ids=["find_edges"],
)
def test_should_return_edges_of_image(self, image: Image, expected: Image) -> None:
image = image.find_edges()
assert image == expected