Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit b6a9327

Browse files
whoiskatrinbosd
authored andcommitted
[IMP] image_processing: Simplify, Always invert the image
Removed the unnecessary if-else block and moved the np.invert() call to the beginning of the function to avoid inverting the image twice if process_background is True. Changed the function always to invert the image if process_background is False. This makes the function more efficient because it avoids the need to perform the inversion and thresholding separately.
1 parent 4842f79 commit b6a9327

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

camelot/image_processing.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,14 @@ def adaptive_threshold(imagename, process_background=False, blocksize=15, c=-2):
3232
numpy.ndarray representing the original image.
3333
threshold : object
3434
numpy.ndarray representing the thresholded image.
35-
3635
"""
3736
img = cv2.imread(imagename)
3837
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
39-
40-
if process_background:
41-
threshold = cv2.adaptiveThreshold(
42-
gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, blocksize, c
43-
)
44-
else:
45-
threshold = cv2.adaptiveThreshold(
46-
np.invert(gray),
47-
255,
48-
cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
49-
cv2.THRESH_BINARY,
50-
blocksize,
51-
c,
52-
)
38+
if not process_background:
39+
gray = np.invert(gray)
40+
threshold = cv2.adaptiveThreshold(
41+
gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, blocksize, c
42+
)
5343
return img, threshold
5444

5545

0 commit comments

Comments
 (0)