I have this code that allows you to detect pixels of a vertain value. Right now I'm detecting pixels over a certain value (27). My idea would be to still detect them but to detect another pixel values (I want to detec pixels from 65 to 75, another interval of pixels). How can I do this?
As you may see, T'm detecting grayscale images, so I have this same value for red, green and blue.
Any idea to improve this program in order to work faster would be really appreciated. Sucha as using os.walk to introduce all images from the Daytime folder that I don't reaaly know how to do it.
Thanks.
daytime_images = os.listdir("D:/TR/Daytime/")
number_of_day_images = len(daytime_images)
day_value = 27
def find_RGB_day(clouds, red, green, blue):
img = Image.open(clouds)
img = img.convert('RGB')
pixels_single_photo = []
for x in range(img.size[0]):
for y in range(img.size[1]):
h, s, v, = img.getpixel((x, y))
if h <= red and s <= green and v <= blue:
pixels_single_photo.append((x,y))
return pixels_single_photo
number = 0
for _ in range(number_of_day_images):
world_image = ("D:/TR/Daytime/" + daytime_images[number])
pixels_found = find_RGB_day(world_image, day_value, day_value, day_value)
coordinates.append(pixels_found)
number = number+1
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…