From: Tahseen on
I have a 24 bit RGB image (bmp) that has 1024X1280X3 pixels and is of
uint8 type (matlab shows it when loading the image using 'imread'). I
would like to multiply it with a 3X3 matrix to see how the image
changes. When I do it using the following command:

Image2 = Matrix * Image1;

I get this message:

"??? Error: ==> mtimes
Integers can only be combined with integers of the same class, or
scalar doubles."

Then I converted Image1 into double using:

DoubleImage = imdouble(Image1);

And then tried to do the multiplication once again:

Image2 = Matrix1 * DoubleImage;

This time I got this error:

"??? Error: ==> mtimes
Input arguments must be 2-D."

Could anyone please tell me how am I going to do the multiplication
and then form the output image for viewing.

Thanks in advance!
From: Herbert Ramoser on
Tahseen wrote:
> I have a 24 bit RGB image (bmp) that has 1024X1280X3 pixels and is of
> uint8 type (matlab shows it when loading the image using 'imread'). I
> would like to multiply it with a 3X3 matrix to see how the image
> changes. When I do it using the following command:
>
> Image2 = Matrix * Image1;
>
> I get this message:
>
> "??? Error: ==> mtimes
> Integers can only be combined with integers of the same class, or
> scalar doubles."
>
> Then I converted Image1 into double using:
>
> DoubleImage = imdouble(Image1);
>
> And then tried to do the multiplication once again:
>
> Image2 = Matrix1 * DoubleImage;
>
> This time I got this error:
>
> "??? Error: ==> mtimes
> Input arguments must be 2-D."
>
> Could anyone please tell me how am I going to do the multiplication
> and then form the output image for viewing.

Two possibilities:
- help immultiply
- Image2 = double(Image1) .* repmat(Matrix1, [1 1 3]);

-Herbert
From: Tahseen on
Herbert Ramoser wrote:
> Two possibilities:
> - help immultiply
> - Image2 = double(Image1) .* repmat(Matrix1, [1 1 3]);
>
> -Herbert

I tried both but they didn't work out. Using 'immultiply' shows that
both the parameters must be of the same size.

Image2=double(Image1).*repmat(Matrix1, [1 1 3]);
shows this error:

"??? Error: ==> times
Array dimensions must match for binary array op."

I think I need to further clarify the problem. Every pixel of the RGB
planes of the image has to be multiplied by Matrix1. For instance,
the first pixel of each of the three planes R1, G1 & B1 will first be
multiplied by Matrix1, then R2, G2 & B2 will be multiplied and so on.
So it should be a 3X3 matrix multiplied by another 3X1 matrix as
follows:

The first pixels of the new image (say XYZ)

[X1 Y1 Z1] = [m11 m12 m13; m21 m22 m23; m31 m32 m33] * [R1 G1 B1];
..
..
..
[Xn Yn Zn] = [m11 m12 m13; m21 m22 m23; m31 m32 m33] * [Rn Gn Bn];

Finally the output image XYZ will have the pixel values X1,..,Xn for
the X plane, Y1,..,Yn for the Y plane and Z1,..,Zn for the Z plane
and show the final image.
From: Herbert Ramoser on
Tahseen wrote:
> Herbert Ramoser wrote:
>
>>Two possibilities:
>>- help immultiply
>>- Image2 = double(Image1) .* repmat(Matrix1, [1 1 3]);
>>
>>-Herbert
>
>
> I tried both but they didn't work out. Using 'immultiply' shows that
> both the parameters must be of the same size.
>
> Image2=double(Image1).*repmat(Matrix1, [1 1 3]);
> shows this error:
>
> "??? Error: ==> times
> Array dimensions must match for binary array op."
>
> I think I need to further clarify the problem. Every pixel of the RGB
> planes of the image has to be multiplied by Matrix1. For instance,
> the first pixel of each of the three planes R1, G1 & B1 will first be
> multiplied by Matrix1, then R2, G2 & B2 will be multiplied and so on.
> So it should be a 3X3 matrix multiplied by another 3X1 matrix as
> follows:
>
> The first pixels of the new image (say XYZ)
>
> [X1 Y1 Z1] = [m11 m12 m13; m21 m22 m23; m31 m32 m33] * [R1 G1 B1];
> .
> .
> .
> [Xn Yn Zn] = [m11 m12 m13; m21 m22 m23; m31 m32 m33] * [Rn Gn Bn];
>
> Finally the output image XYZ will have the pixel values X1,..,Xn for
> the X plane, Y1,..,Yn for the Y plane and Z1,..,Zn for the Z plane
> and show the final image.

Yes, this clarification has been necessary.

Try something like this:

R = double(Image1(:,:,1));
G = double(Image1(:,:,2));
B = double(Image1(:,:,3));
Image2 = Matrix1 * [R(:), G(:), B(:)].';

You need to do some reshaping of Image2.

-Herbert