Skip to content

Commit f167883

Browse files
committed
Replace raw file string with pathlib Path
1 parent 4a3073e commit f167883

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: digital_image_processing/morphological_operations/erosion_operation.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
import numpy as np
24
from PIL import Image
35

@@ -63,11 +65,15 @@ def erosion(image: np.ndarray, kernel: np.ndarray) -> np.ndarray:
6365

6466
if __name__ == "__main__":
6567
# read original image
66-
lena = np.array(Image.open(r"..\image_data\lena.jpg"))
68+
lena_path = Path(__file__).resolve().parent / "image_data" / "lena.jpg"
69+
lena = np.array(Image.open(lena_path))
70+
6771
# kernel to be applied
6872
structuring_element = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])
73+
6974
# Apply erosion operation to a binary image
7075
output = erosion(gray_to_binary(rgb_to_gray(lena)), structuring_element)
76+
7177
# Save the output image
7278
pil_img = Image.fromarray(output).convert("RGB")
7379
pil_img.save("result_erosion.png")

0 commit comments

Comments
 (0)