I have pictures that present with black bars above and below the image:
The black bars are at a different height in the picture at different pictures. I want to remove the black bars from each picture and save a new picture to a folder. I googled a bit and found the following code (adapted for my needs).
Now, the problem is that the saved image still has the black bars. When I use getpixel to return the RGB value, it returns it as 0,0,0. Does anyone have any ideas?
from PIL import Image, ImageOps
from os import listdir
from os.path import isfile, join
import numpy
mypath_cut = "Redacted Path to Image"
onlyfiles_cut = [f for f in listdir(mypath_cut) if isfile(join(mypath_cut, f))]
StimulusNumber = 0
for image in onlyfiles_cut:
im = Image.open('Cow Pictures/Cut Pictures/{}'.format(image)).convert('RGB')
na = numpy.array(im)
blackY, blackX = numpy.where(numpy.all(na==[0,0,0], axis = 2))
top, bottom = blackY[0], blackY[-1]
left, right = blackX[0], blackX[-1]
ROI = na[top:bottom, left:right]
StimulusNumber += 1
Image.fromarray(ROI).save("Cow Pictures/Cut Pictures/Cut_NoBlack/Cow{}.jpg".format(StimulusNumber))```

