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:
Rearranging array values based on location within array

Subject: Rearranging array values based on location within array

From: Eric

Date: 11 Nov, 2009 02:31:01

Message: 1 of 3

Hello, I am new to Matlab and trying to learn as much as I can.

I've imported a multiframe TIFF image using the imread command and now have a 3 dimensional matrix. I'm looking for the most efficient/easiest way to reorganize this M by N by P matrix into a 4-column matrix where columns 1,2,3 are the M, N, P coordinates of values (the pixel locations) within the array and column 4 is the value (in this case grayscale value of the image) at that given pixel.

Thank you for your time and any insight you can provide to me.

Best,

Eric

Subject: Rearranging array values based on location within array

From: Naresh Pai

Date: 11 Nov, 2009 04:07:01

Message: 2 of 3

"Eric " <ethorhauer@gmail.com> wrote in message <hdd7l5$p8q$1@fred.mathworks.com>...
> Hello, I am new to Matlab and trying to learn as much as I can.
>
> I've imported a multiframe TIFF image using the imread command and now have a 3 dimensional matrix. I'm looking for the most efficient/easiest way to reorganize this M by N by P matrix into a 4-column matrix where columns 1,2,3 are the M, N, P coordinates of values (the pixel locations) within the array and column 4 is the value (in this case grayscale value of the image) at that given pixel.
>
> Thank you for your time and any insight you can provide to me.
>
> Best,
>
> Eric

% Load image
image = imread('image.tif');

% Reshape as each layer column vector
M = reshape(image(:,:,1),numel(image(:,:,1)),1);
N = reshape(image(:,:,2),numel(image(:,:,1)),1);
P = reshape(image(:,:,3),numel(image(:,:,1)),1);

% concatenate
final =[M N P];

Try this. You might shorten this code further - Naresh

Subject: Rearranging array values based on location within array

From: Matt Fig

Date: 11 Nov, 2009 04:53:03

Message: 3 of 3

Maybe my lack of image processing knowledge will show here, but it seems your question doesn't make sense. For example, if we have the 3-D array:


x = round(rand(2,3,3)*100) % A sample image.

Then the gray-scale is some sort of weighted average of the values across the third dimension:

gs = mean(x,3); % A simple mean for example.

Then you would only need three columns to store the pixel locations and gray-scale values:

[r,c,p] = size(x);
[T(:,1),T(:,2)] = ind2sub([r,c],1:r*c);
mn = mean(x,3);
T(:,3) = mn(:)

As I said, I might have missed something about the image processing aspect. Hopefully this will give you an idea anyway.

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