How can I multiply matrix of vectors by matrix?

I have an RGB image, which is [width, height, 3] array. How can I multiply every pixel ([R, G, B] vector) by matrix (this is conversion RGB -> YIQ, but without rgb2ntsc function)? Also, it should be done without any loops.

답변 (1개)

Brian B
Brian B 2013년 3월 2일
편집: Brian B 2013년 3월 2일

0 개 추천

Not without loops, but hiding them inside bsxfun...
M = rand(140,160,3); % image data
T = randn(3); % transformation matrix, [y; i; q] = T*[r; g; b]
TM = cat(3, sum( bsxfun(@times, M, reshape(T(1,:), 1, 1, [])), 3), ...
sum( bsxfun(@times, M, reshape(T(2,:), 1, 1, [])), 3), ...
sum( bsxfun(@times, M, reshape(T(3,:), 1, 1, [])), 3));

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품

질문:

2013년 3월 2일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by