text: I am working on a basic Image processing task - to conduct pixel based matrix operations given a matrix transformation formula. I am reading through pixel values (gives me a 1*3 tuple) from a (x,y) pixel location in the image and doing matrix operations using numpy, which returns numpy.ndarray's and finally I am required to store the transformed pixel values in a 2d matrix, each (x,y) co-ordinate storing a (1*3) vector of transformed pixel value.
  def colortrans(im): #(X,Y,Z) = T + [M](*(RGB)(1*3 Vector) # (X,Y,X) = (1*3 tuple) # T = [0,128,128], (a 1*3 vector) # M = (3*3 Matrix) # RGB = (1*3 Vector) pix = im.load() x,y = im.size ycc = [] #print(ycc.shape) m1 = np.array([[0],[128],[128]]) print(type(m1)) m2 = np.array([[0.299,0.587,0.114],[-0.168736,-0.331264,0.5],[0.5,-0.418688,-0.081312]]) print(m2) for i in range(x): for j in range(y): m = m1.T+np.dot(m2,np.array(pix[i,j])) #print(m.shape) #print(type(m)) ycc.append(m) #ycc=np.array(ycc) print(ycc[1:5]) mat_ycc = np.reshape(ycc,(x,y)) print(len(ycc)) print (x, y) mat_ycc = np.reshape(ycc,(x,y)) return mat_ycc
  I want something like this, a format which can be transformed into an image
  [(180,128,128),(167,128,128) ... ]
  I get this(this format doesn't allow me to reshape as dims doesn't agree)
  [array([[180., 128., 128.]]), array([[167., 128., 128.]]), array([[157., 128., 128.]]), array([[178.772 , 127. , 128.162624]])]
  Error I get
  len(ycc) = 409600 Image size = 640*640
  The error I get is :
  ValueError: cannot reshape array of size 1228800 into shape (640,640)
  I think you are following a little complicated way. I have little suggestion:
  Create a U = np.zeroes(x,y,3)
  apply for loop on 2 dimensional image