mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-26 10:58:40 +00:00
Replace raw file string with pathlib Path
This commit is contained in:
parent
4a3073e2e3
commit
f1678839ad
@ -1,3 +1,5 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
@ -63,11 +65,15 @@ def erosion(image: np.ndarray, kernel: np.ndarray) -> np.ndarray:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# read original image
|
# read original image
|
||||||
lena = np.array(Image.open(r"..\image_data\lena.jpg"))
|
lena_path = Path(__file__).resolve().parent / "image_data" / "lena.jpg"
|
||||||
|
lena = np.array(Image.open(lena_path))
|
||||||
|
|
||||||
# kernel to be applied
|
# kernel to be applied
|
||||||
structuring_element = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])
|
structuring_element = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])
|
||||||
|
|
||||||
# Apply erosion operation to a binary image
|
# Apply erosion operation to a binary image
|
||||||
output = erosion(gray_to_binary(rgb_to_gray(lena)), structuring_element)
|
output = erosion(gray_to_binary(rgb_to_gray(lena)), structuring_element)
|
||||||
|
|
||||||
# Save the output image
|
# Save the output image
|
||||||
pil_img = Image.fromarray(output).convert("RGB")
|
pil_img = Image.fromarray(output).convert("RGB")
|
||||||
pil_img.save("result_erosion.png")
|
pil_img.save("result_erosion.png")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user