Skip to content

Commit

Permalink
[IMP] image_processing: Simplify, Always invert the image
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
whoiskatrin authored and bosd committed Oct 7, 2024
1 parent 4842f79 commit b6a9327
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions camelot/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,14 @@ def adaptive_threshold(imagename, process_background=False, blocksize=15, c=-2):
numpy.ndarray representing the original image.
threshold : object
numpy.ndarray representing the thresholded image.
"""
img = cv2.imread(imagename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

if process_background:
threshold = cv2.adaptiveThreshold(
gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, blocksize, c
)
else:
threshold = cv2.adaptiveThreshold(
np.invert(gray),
255,
cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
cv2.THRESH_BINARY,
blocksize,
c,
)
if not process_background:
gray = np.invert(gray)
threshold = cv2.adaptiveThreshold(
gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, blocksize, c
)
return img, threshold


Expand Down

0 comments on commit b6a9327

Please sign in to comment.