Critical fix: Update img_gray after first crop in remove_black_borders
Browse files
app.py
CHANGED
|
@@ -51,7 +51,7 @@ def remove_black_borders(img, black_th=5):
|
|
| 51 |
"""Remove black borders from retinal images"""
|
| 52 |
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
| 53 |
|
| 54 |
-
# x axis
|
| 55 |
centre_y = img_gray.shape[1] // 2
|
| 56 |
black_list = img_gray[:, centre_y]
|
| 57 |
black_list = np.where(black_list >= black_th)[0]
|
|
@@ -60,8 +60,9 @@ def remove_black_borders(img, black_th=5):
|
|
| 60 |
first_non_black = black_list[0]
|
| 61 |
reverse_first_non_black = black_list[-1] + 1
|
| 62 |
img = img[first_non_black:reverse_first_non_black, :, :]
|
|
|
|
| 63 |
|
| 64 |
-
# y axis
|
| 65 |
centre_x = img_gray.shape[0] // 2
|
| 66 |
black_list = img_gray[centre_x, :]
|
| 67 |
black_list = np.where(black_list >= black_th)[0]
|
|
|
|
| 51 |
"""Remove black borders from retinal images"""
|
| 52 |
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
| 53 |
|
| 54 |
+
# x axis (vertical crop)
|
| 55 |
centre_y = img_gray.shape[1] // 2
|
| 56 |
black_list = img_gray[:, centre_y]
|
| 57 |
black_list = np.where(black_list >= black_th)[0]
|
|
|
|
| 60 |
first_non_black = black_list[0]
|
| 61 |
reverse_first_non_black = black_list[-1] + 1
|
| 62 |
img = img[first_non_black:reverse_first_non_black, :, :]
|
| 63 |
+
img_gray = img_gray[first_non_black:reverse_first_non_black, :] # Update gray image too!
|
| 64 |
|
| 65 |
+
# y axis (horizontal crop)
|
| 66 |
centre_x = img_gray.shape[0] // 2
|
| 67 |
black_list = img_gray[centre_x, :]
|
| 68 |
black_list = np.where(black_list >= black_th)[0]
|