From f7f4855be53d0baee3ab8ec08e9c307941484488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Cancio?= Date: Fri, 3 Oct 2025 18:56:59 +0200 Subject: [PATCH] Add doctests to convert_to_negative Contributes to #9943 --- .../convert_to_negative.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/digital_image_processing/convert_to_negative.py b/digital_image_processing/convert_to_negative.py index 9bf2d8f2c075..b55aa1419459 100644 --- a/digital_image_processing/convert_to_negative.py +++ b/digital_image_processing/convert_to_negative.py @@ -2,10 +2,32 @@ Implemented an algorithm using opencv to convert a colored image into its negative """ +import numpy as np from cv2 import destroyAllWindows, imread, imshow, waitKey def convert_to_negative(img): + """ + Convert an image to its negative. + + Args: + img: NumPy array representing the image (BGR format) + + Returns: + NumPy array with inverted colors + + >>> import numpy as np + >>> img = np.array([[[100, 150, 200]]], dtype=np.uint8) + >>> result = convert_to_negative(img.copy()) + >>> result[0][0].tolist() + [155, 105, 55] + >>> img2 = np.array([[[0, 0, 0]], [[255, 255, 255]]], dtype=np.uint8) + >>> neg = convert_to_negative(img2.copy()) + >>> neg[0][0].tolist() + [255, 255, 255] + >>> neg[1][0].tolist() + [0, 0, 0] + """ # getting number of pixels in the image pixel_h, pixel_v = img.shape[0], img.shape[1]