Skip to content

Commit f7f4855

Browse files
committed
Add doctests to convert_to_negative
Contributes to #9943
1 parent a71618f commit f7f4855

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎digital_image_processing/convert_to_negative.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,32 @@
22
Implemented an algorithm using opencv to convert a colored image into its negative
33
"""
44

5+
import numpy as np
56
from cv2 import destroyAllWindows, imread, imshow, waitKey
67

78

89
def convert_to_negative(img):
10+
"""
11+
Convert an image to its negative.
12+
13+
Args:
14+
img: NumPy array representing the image (BGR format)
15+
16+
Returns:
17+
NumPy array with inverted colors
18+
19+
>>> import numpy as np
20+
>>> img = np.array([[[100, 150, 200]]], dtype=np.uint8)
21+
>>> result = convert_to_negative(img.copy())
22+
>>> result[0][0].tolist()
23+
[155, 105, 55]
24+
>>> img2 = np.array([[[0, 0, 0]], [[255, 255, 255]]], dtype=np.uint8)
25+
>>> neg = convert_to_negative(img2.copy())
26+
>>> neg[0][0].tolist()
27+
[255, 255, 255]
28+
>>> neg[1][0].tolist()
29+
[0, 0, 0]
30+
"""
931
# getting number of pixels in the image
1032
pixel_h, pixel_v = img.shape[0], img.shape[1]
1133

0 commit comments

Comments
 (0)