0 votes
1 view
in Python by (50.5k points)

I am having an image described with a Numpy array, i.e. each pixel is an array [r,g,b]. Now, I need to transform it to YUV using matrix multiplication and trying not to use loops.


self.yuv=dot([[   0.299,  0.587,    0.114  ],

              [-0.14713, -0.28886,  0.436  ],

              [   0.615, -0.51499, -0.10001]], 


I get the error - objects not aligned. I guess that's because of self. yuv[i,j] is not a perpendicular vector. 

1 Answer

0 votes
by (108k points)

Please be informed that your matrix has shape (3, 3) while your figure has shape (rows, cols, 3) and np.dot does "a sum-product over the last axis of a and the second-to-last of b."

You just need to reverse the order of the operands inside np.dot and then perform the transpose your conversion matrix:

rgb2yuv = np.array([[0.299, 0.587, 0.114],

                    [-0.14713, -0.28886, 0.436],

                    [0.615, -0.51499, -0.10001]])

self.yuv = np.dot(self.rgb, rgb2yuv.T)

For the best of career growth, check out Intellipaat’s Python Course and get certified!


Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 27, 2019 in Data Science by sourav (17.6k points)
0 votes
1 answer
asked Nov 30, 2020 in Python by ashely (50.5k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !