import numpy as np
from pandas import DataFrame, Series
from skimage import io
= io.imread("https://upload.wikimedia.org/wikipedia/commons/thumb/9/97/Swallow-tailed_bee-eater_%28Merops_hirundineus_chrysolaimus%29.jpg/768px-Swallow-tailed_bee-eater_%28Merops_hirundineus_chrysolaimus%29.jpg")
photo
= np.array(photo, dtype=np.float64) / 255 # Scale values
photo = original_shape = tuple(photo.shape) # Get the current shape
w, h, d = np.reshape(photo, (w * h, d)) # Reshape to to 2D
image_array
= DataFrame(image_array, columns=["Red", "Green", "Blue"]) pixels
To find the index of the pixel with the largest blue value, we use idxmax()
on the Blue
column.
= pixels["Blue"].idxmax() bluest_index
We use the width, w
, of the original image as the denominator for a division and a modulo.
= bluest_index % w
x = bluest_index // w
y x, y
(537, 150)