As you know looping through each pixels and accessing their values with opencv takes too long. As a beginner I'm trying to learn opencv myself when I tried this approach it took me around 7-10 seconds of time to loop through image and perform operations.
code is as below
original_image = cv2.imread(img_f)
image = np.array(original_image)
for y in range(image.shape[0]):
for x in range(image.shape[1]):
# remove grey background
if 150 <= image[y, x, 0] <= 180 and \
150 <= image[y, x, 1] <= 180 and \
150 <= image[y, x, 2] <= 180:
image[y, x, 0] = 0
image[y, x, 1] = 0
image[y, x, 2] = 0
# remove green dashes
if image[y, x, 0] == 0 and \
image[y, x, 1] == 169 and \
image[y, x, 2] == 0:
image[y, x, 0] = 0
image[y, x, 1] = 0
image[y, x, 2] = 0
in above code i'm just trying to remove grey and green pixel colors.
I found similar question asked here but im not able to understand how to use numpy in my usecase as i'm beginner in python and numpy.
Any help or suggestion for solving this will be appreciated thanks