Created
November 16, 2019 17:01
Finding ROI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def borders(here_img, thresh): | |
size = here_img.shape | |
check = int(115 * size[0] / 600) | |
image = here_img[:] | |
top, bottom = 0, size[0] - 1 | |
#plt.imshow(image) | |
#plt.show() | |
shape = size | |
#find the background color for empty column | |
bg = np.repeat(thresh, shape[1]) | |
count = 0 | |
for row in range(1, shape[0]): | |
if (np.equal(bg, image[row]).any()) == True: | |
#print(count) | |
count += 1 | |
else: | |
count = 0 | |
if count >= check: | |
top = row - check | |
break | |
shape = image.shape | |
bg = np.repeat(thresh, shape[1]) | |
count = 0 | |
rows = np.arange(1, shape[0]) | |
#print(rows) | |
for row in rows[::-1]: | |
if (np.equal(bg, image[row]).any()) == True: | |
count += 1 | |
else: | |
count = 0 | |
if count >= check: | |
bottom = row + count | |
break | |
#print(count) | |
#plt.imshow(here_img[top:bottom, :]) | |
#plt.imshow(here_img[top:bottom, :]) | |
#plt.show() | |
d1 = (top - 2) >= 0 | |
d2 = (bottom + 2) < size[0] | |
d = d1 and d2 | |
if(d): | |
b = 2 | |
else: | |
b = 0 | |
return (top, bottom, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment