1

As I have no much knowledge in opencv, the question might be silly. Anyways my question is, I have a set of 30 images and I am calculating the mean of Red, Green and Blue channles for all the 30 images and stored them in 3 different lists, now what I want is to append these 3 different list values into a 3D array as:

[B_mean,
 G_mean,
 R_mean]

This is my BGR mean values:

blue mean [25, 28, 66, 63, 59, 70, 64, 38, 33, 39, 22, 37, 48, 4, 13, 12, 6, 3, 22, 18, 23, 21, 22, 31, 38, 21, 34, 26, 21, 30]
green mean [27, 29, 68, 66, 63, 69, 66, 45, 48, 41, 38, 41, 41, 22, 21, 9, 7, 25, 35, 28, 37, 36, 35, 32, 36, 20, 27, 24, 18, 25]
read mean [25, 26, 70, 69, 71, 67, 66, 42, 45, 31, 40, 43, 37, 32, 33, 37, 30, 34, 34, 24, 28, 32, 30, 33, 36, 26, 24, 30, 24, 26]

like 3 rows and 30 columns. so how am I going to get this?

Thanks!

1
  • It sounds like you want a 2d array, ie a (3, 30) array. A 3d array would have a shape like (2, 3, 30). Commented Feb 21, 2014 at 18:46

3 Answers 3

1

Just use numpy.array:

import numpy as np

red = range(0, 30)
blue = range(10, 40)
green = range(20, 50)
array = np.array([red, green, blue])
print array.shape
# (3, 30)
Sign up to request clarification or add additional context in comments.

Comments

0

It's actually a two-dimensional array if you only have rows and columns.

mylist = [[1,2,3], [1,2,3]]
mylist.append([1,2,3])

This will create a list of three RGB pairs (1, 2, 3) in this case.

Edit

After re-reading your question, a more specific solution would be (given three lists of colors):

mylist = []
for i in range(0, 30):
   mylist.append([red[i], green[i], blue[i]])

Comments

0
matrix = [[mean for mean in chan]  for chan in [red, green, blue]]

This is how you initialize a multidimensional Array in Python.

Edit: I should mention that using numpy is the preferred way unless you're writing something one-time-use-only.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.