IcySnow
IcySnow

Reputation: 871

Matlab work with each vector from a 4D array

I have a 4D matrix of size, let's say, 100x200x3x10 where 100x200 is the size of one image, 3 is the number of channels (RGB images) and 10 is the number of images.

I want to compute the inner product of each RGB vector in each image with itself. The resulting image should be of size 100x200x10. How can I efficiently compute these products, possibly without the use of loops?

Thanks.

Upvotes: 0

Views: 217

Answers (1)

David
David

Reputation: 8459

If you call your matrix M, this should work:

squeeze(dot(M,M,3))

The squeeze is because matlab gives a 100x200x1x10 matrix as the result, and squeeze knocks out the redundant dimension.

Upvotes: 4

Related Questions