MATLAB: How to multiply 3*3 matrix to RGB values in and image

anaglyphmatrixmatrix manipulation

Dear matlab developers, I am new to matlab,I need your help in this please. I have this formula that generates anaglyph images. I would like to know how to code it in matlab to input as an image and the output will be anaglyph image.

Best Answer

RGB1 = rand(100, 100, 3);
RGB2 = rand(100, 100, 3);
RGBa = cat(3, 0.299 * RGB1(:, :, 1) + 0.587 * RGB1(:, :, 2) + 0.144 * RGB1(:, :, 3), ...
zeros(size(RGB1, 1), size(RGB1, 2)), ...
0.299 * RGB2(:, :, 1) + 0.587 * RGB2(:, :, 2) + 0.144 * RGB2(:, :, 3));