Skip to content

Commit

Permalink
Merge branch 'main' into 289-adjust-brightness-and-contrast-of-image
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipGutberlet authored Jun 16, 2023
2 parents 67766e7 + 3444700 commit 4e0fdf2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/safeds/data/image/containers/_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,24 @@ def blur(self, radius: int = 1) -> Image:
new_image._image = new_image._image.filter(ImageFilter.BoxBlur(radius))
return new_image

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

def invert_colors(self) -> Image:
"""
Return the image with inverted colors.
Expand Down
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.
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.
17 changes: 17 additions & 0 deletions tests/safeds/data/image/containers/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,20 @@ def test_should_crop_png_image(self) -> None:
image = image.crop(0, 0, 100, 100)
image2 = Image.from_png_file(resolve_resource_path("image/whiteCropped.png"))
assert image == image2


class TestSharpen:
@pytest.mark.parametrize("factor", [-1, 0.5, 10])
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)
image2.to_png_file(resolve_resource_path("image/sharpen/sharpened_by_" + str(factor) + ".png"))
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

0 comments on commit 4e0fdf2

Please sign in to comment.