How can I multiply matrix of vectors by matrix?

1 回表示 (過去 30 日間)
Viktor
Viktor 2013 年 3 月 2 日
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 日
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));

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by