0
$\begingroup$

How can I find the mean for each of the channels (RGB) across an array of images?

For example train_dataset[0]['image'].shape is (600, 800, 3) and len(train_dataset) is 720 meaning it includes 720 images of dimension 600x800 and 3 channels. train_dataset[0]['image'] is an ndarray.

I am looking to end up with 3 numbers each representing the mean for each of the channels across all these 720 images.

I have this very dumb solution but I wonder if there's a better solution? enter image description here

I also did it this other way and got almost the same answer: enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

Could probably be more elegant, but here's an idea:

mean[:, :, 0:2] = np.mean(imgs[:, :, :, 0:2], axis=0)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.