Python Forum

Full Version: how to analayze only a part of an image?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
lets say i wanted to counte the black pixels in the bottom right 200x200 pixels of every image.
i have:
my_list = []
for root, dirs, files in os.walk("E:/1/1/"):  
    for filename in files:
        my_list.append(filename)

cpt1 = sum([len(files) for r, d, files in os.walk('E:/1/1')])
i = 0
increment1 = ('E:/1/1/' + my_list[i])
black = 0
red = 0

while (i) < cpt1-2:
  i += 1
  increment1 = ('E:/1/1/' + my_list[i])
  black1 = 0
  im1 = Image.open(str(increment1))
  rgb_im1 = im1.convert('RGB')
  width1, height1 = imagesize.get(str(increment1))
  totalpixels1 = width1*height1
  for pixel in rgb_im1.getdata():
     if pixel == (0, 0, 0): 
      black1 += 1
     else:
      red += 1
And what is your question ?
It would be good, if you publish the whole code, not part of it.