Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
matrix conversion

Subject: matrix conversion

From: Z A

Date: 16 May, 2010 14:18:03

Message: 1 of 8

Hello,

I would like to convert a m x n x 9 matrix into m x n x 3 matrix. May anyone kindly assist me in doing so.

Best
Z

Subject: matrix conversion

From: Michael_RW

Date: 16 May, 2010 14:59:53

Message: 2 of 8

Try "reshape".

---
frmsrcurl: http://compgroups.net/comp.soft-sys.matlab/matrix-conversion

Subject: matrix conversion

From: Roger Stafford

Date: 16 May, 2010 16:51:04

Message: 3 of 8

"Z A" <nospam-rekabi570@yahoo.ca> wrote in message <hsouqr$qoj$1@fred.mathworks.com>...
> I would like to convert a m x n x 9 matrix into m x n x 3 matrix.

  There are three elements in the former for every one element in the latter. In what way would you like to combine each three elements into one? Or do you want to discard 6*m*n of them, and if so which ones?

Roger Stafford

Subject: matrix conversion

From: Z A

Date: 16 May, 2010 17:15:05

Message: 4 of 8

I tried reshape however I get an error, obviously because I want a M x N x 3 and so I will not hav ethe same elements.
This is what I want:
I have an image which is composed of 420 x 560 x 3 unit8, I can do womething like rgb2gray to get 420 x 560 double. However my second image is 420 x 560 x 9, I cannot overlay that as a transperency onto the first one, because the dimensions are different, what I want is to change that matrix to 420 x 560 x 3 so I can do that without losing any info. I hope you understood what I need. Thank you in advance.
Z

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hsp7po$pkg$1@fred.mathworks.com>...
> "Z A" <nospam-rekabi570@yahoo.ca> wrote in message <hsouqr$qoj$1@fred.mathworks.com>...
> > I would like to convert a m x n x 9 matrix into m x n x 3 matrix.
>
> There are three elements in the former for every one element in the latter. In what way would you like to combine each three elements into one? Or do you want to discard 6*m*n of them, and if so which ones?
>
> Roger Stafford

Subject: matrix conversion

From: Walter Roberson

Date: 16 May, 2010 18:16:24

Message: 5 of 8

Z A wrote:
> I tried reshape however I get an error, obviously because I want a M x N
> x 3 and so I will not hav ethe same elements.
> This is what I want:
> I have an image which is composed of 420 x 560 x 3 unit8, I can do
> womething like rgb2gray to get 420 x 560 double. However my second image
> is 420 x 560 x 9, I cannot overlay that as a transperency onto the first
> one, because the dimensions are different, what I want is to change that
> matrix to 420 x 560 x 3 so I can do that without losing any info.

The first image is x 3 because it is a true-color image, with the third
dimension being red, green, and blue.

The second image... x 9 is either a mistake or an indication that it is
really 9 grayscale or indexed images stacked together.

The only way to pack down a 420 x 560 x 9 matrix to 420 x 560 x 3 matrix
without losing any information is by representing the information
differently, such as

new(:,:,1) = old(:,:,1) * 65536 + old(:,:,2) * 256 + old(:,:,3);
new(:,:,2) = old(:,:,4) * 65536 + old(:,:,5) * 256 + old(:,:,6);

and so on.

However, data packet in such a manner would not be suitable for use as a
transparency.

You are going to have to explore _why_ the second image is x 9; it is
fairly unlikely that it represents a single image.

Subject: matrix conversion

From: Z A

Date: 16 May, 2010 18:59:04

Message: 6 of 8

Hello walter,

Thank you kindly for your reply. I am invoking the following
http://blogs.mathworks.com/steve/2009/02/18/image-overlay-using-transparency/
from steve's blog, and following his method I get that x 9 matrix, which is confusing me alot.
Tha x 9 image is the green image you see in his blog.

Best
Z

Walter Roberson <roberson@hushmail.com> wrote in message <YDWHn.12979$TL5.6183@newsfe24.iad>...
> Z A wrote:
> > I tried reshape however I get an error, obviously because I want a M x N
> > x 3 and so I will not hav ethe same elements.
> > This is what I want:
> > I have an image which is composed of 420 x 560 x 3 unit8, I can do
> > womething like rgb2gray to get 420 x 560 double. However my second image
> > is 420 x 560 x 9, I cannot overlay that as a transperency onto the first
> > one, because the dimensions are different, what I want is to change that
> > matrix to 420 x 560 x 3 so I can do that without losing any info.
>
> The first image is x 3 because it is a true-color image, with the third
> dimension being red, green, and blue.
>
> The second image... x 9 is either a mistake or an indication that it is
> really 9 grayscale or indexed images stacked together.
>
> The only way to pack down a 420 x 560 x 9 matrix to 420 x 560 x 3 matrix
> without losing any information is by representing the information
> differently, such as
>
> new(:,:,1) = old(:,:,1) * 65536 + old(:,:,2) * 256 + old(:,:,3);
> new(:,:,2) = old(:,:,4) * 65536 + old(:,:,5) * 256 + old(:,:,6);
>
> and so on.
>
> However, data packet in such a manner would not be suitable for use as a
> transparency.
>
> You are going to have to explore _why_ the second image is x 9; it is
> fairly unlikely that it represents a single image.

Subject: matrix conversion

From: Walter Roberson

Date: 16 May, 2010 19:14:30

Message: 7 of 8

Z A wrote:
> Hello walter,
>
> Thank you kindly for your reply. I am invoking the following
> http://blogs.mathworks.com/steve/2009/02/18/image-overlay-using-transparency/
>
> from steve's blog, and following his method I get that x 9 matrix, which
> is confusing me alot.
> Tha x 9 image is the green image you see in his blog.

S1 = size(E,1);
S2 = size(E,2);
green = cat(3, zeros(S1,S2), ones(S1,S2), zeros(S1,S2));

Subject: matrix conversion

From: ImageAnalyst

Date: 16 May, 2010 20:20:37

Message: 8 of 8

The green image is a true color N by M by 3 image. There is no 9
plane image. Read his explanation again carefully. He had an N by M
image, then he locked that down with "hold on" and put a N by M by 3
green image on top of it, essentially covering up the monochrome
image. Then he used a different N by M image to modify the
transparency of the green image which was sitting on top of the
monochrome image, thus letting the monochrome image show through in
some parts.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us