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: sharpen image #364

Merged
merged 19 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2830d66
completed titanic tutorial in getting_started.ipynb
daniaHu Jun 16, 2023
0b104ee
Merge remote-tracking branch 'origin/286-sharpen-image' into 286-shar…
patrikguempel Jun 16, 2023
1e8a976
added sharpening feature
patrikguempel Jun 16, 2023
a8ef0a6
added sharpening feature
patrikguempel Jun 16, 2023
cf34c19
Merge remote-tracking branch 'origin/286-sharpen-image' into 286-shar…
patrikguempel Jun 16, 2023
f4a5401
style: apply automated linter fixes
megalinter-bot Jun 16, 2023
39d4727
used smaller images
patrikguempel Jun 16, 2023
1b25a22
Merge remote-tracking branch 'origin/286-sharpen-image' into 286-shar…
patrikguempel Jun 16, 2023
f677729
Update tests/safeds/data/image/containers/test_image.py
patrikguempel Jun 16, 2023
c1a37d3
added further tests
patrikguempel Jun 16, 2023
1429ea7
Merge remote-tracking branch 'origin/286-sharpen-image' into 286-shar…
patrikguempel Jun 16, 2023
cf279a2
Merge remote-tracking branch 'origin/286-sharpen-image' into 286-shar…
patrikguempel Jun 16, 2023
ce5efff
Merge remote-tracking branch 'origin/286-sharpen-image' into 286-shar…
patrikguempel Jun 16, 2023
12e518b
Merge branch 'main' of https://github.com/Safe-DS/Stdlib into 286-sha…
patrikguempel Jun 16, 2023
ff5527e
style: apply automated linter fixes
megalinter-bot Jun 16, 2023
6695c23
edited test
patrikguempel Jun 16, 2023
6a4749f
Merge branch 'main' of https://github.com/Safe-DS/Stdlib into 286-sha…
patrikguempel Jun 16, 2023
0e06cc4
Merge remote-tracking branch 'origin/286-sharpen-image' into 286-shar…
patrikguempel Jun 16, 2023
0277126
style: apply automated linter fixes
megalinter-bot Jun 16, 2023
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
19 changes: 19 additions & 0 deletions src/safeds/data/image/containers/_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, BinaryIO

import PIL
from PIL import ImageEnhance
from PIL.Image import Image as PillowImage
from PIL.Image import open as open_image

Expand Down Expand Up @@ -246,3 +247,21 @@ def flip_horizontally(self) -> Image:
imagecopy = copy.deepcopy(self)
imagecopy._image = self._image.transpose(PIL.Image.FLIP_LEFT_RIGHT)
return imagecopy

def sharpen(self, factor: float) -> Image:
"""
Return the sharpened image.

Parameters
----------
factor: The amount of sharpness to be applied to the image.
Factor 1.0 is considered to be neutral and does not make any changes.

Returns
-------
result : Image
The image sharpened by the given factor.
"""
image_copy = copy.deepcopy(self)
image_copy._image = ImageEnhance.Sharpness(image_copy._image).enhance(factor)
return image_copy
Binary file added tests/resources/image/sharpen/sharpened_by_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/resources/image/sharpen/to_sharpen.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 @@ -247,3 +247,19 @@ def test_should_be_original(self) -> None:
image = Image.from_png_file(resolve_resource_path("image/original.png"))
image2 = image.flip_horizontally().flip_horizontally()
assert image == image2


class TestSharpen:
@pytest.mark.parametrize("factor", [2, 25])
def test_should_sharpen(self, factor: float) -> None:
image = Image.from_png_file(resolve_resource_path("image/sharpen/to_sharpen.png"))
image2 = image.sharpen(factor)
assert image != image2
assert image2 == Image.from_png_file(
resolve_resource_path("image/sharpen/sharpened_by_" + str(factor) + ".png"),
)

def test_should_not_sharpen(self) -> None:
image = Image.from_png_file(resolve_resource_path("image/sharpen/to_sharpen.png"))
image2 = image.sharpen(1)
assert image == image2