I am trying to crop an image (cropping the background out of a school picture) using matplotlib
, os.path
, and numpy
.
My idea was to section the image off into squares other than the part I needed and then manipulate the alpha channel to make those areas transparent so all I was left with was the part I needed. I have a start to the code but got stuck on the same error message.
I've tried to make some kind of circle mask to crop the face out but the concept of a mask is still foreign to me so I figured this would be easier.
fig, ax = plt.subplots(1, 1)
# Show the image data in a subplot
ax.imshow(img, interpolation='none')
# Show the figure on the screen
row = len(img)
column = len(img[0])
for row in range(0, 231) :
for column in range(0, 330) :
img[row][column] = [0, 0, 0, 0]
fig.show()
Results: 26 for row in range(0, 231) :
27 for column in range(0, 330) :
---> 28 img[row][column] = [0, 0, 0]
29
30
IndexError: index 288 is out of bounds for axis 0 with size 288