I want to separate my image's channels. Then, I want to apply Otsu Thresholding to each one, and finally, merge them together. However, in line 4 of my code, it gives me the following error:
File "C:/Users/Berke/PycharmProjects/goruntu/main.py", line 28, in <module>
image_channels = np.split(np.asarray(gradient_image), 3, axis=2)
File "C:\Users\Berke\PycharmProjects\goruntu\venv\lib\site-packages\numpy\lib\shape_base.py", line 846, in split
N = ary.shape[axis]
IndexError: tuple index out of range
Here's my code:
morph = mypic.copy()
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 1))
myImage = cv2.morphologyEx(morph, cv2.MORPH_GRADIENT, kernel)
myImageChannels = np.split(np.asarray(gradient_image), 3, axis=2)
for channels in range(3):
_, myImageChannels[channels] = cv2.threshold(myImageChannels[channels],
0,
255,
cv2.THRESH_OTSU | cv2.THRESH_BINARY)