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:
Seeking Best Hyperspectral-Image Reshaping (Planer to pixel interleaved) for Speed

Subject: Seeking Best Hyperspectral-Image Reshaping (Planer to pixel interleaved) for Speed

From: Pat Finder

Date: 15 May, 2009 15:08:02

Message: 1 of 6

Questions:
1. Is there a better way?
2. Is there a faster way?

I am working on a hyperspectral image that is 4096x512 by 187 bands.

I'm doing classification, but it is very slow because every time I want to classify a pixel, I need to go to 187 places in memory.

I am thinking that I need to reshape the image so that all the band data is right next to each other in memory, and then transpose it...

Here is some simple code for a small matrix that shows what I think I need to do:

    mm = ones(2);
    mm(:,:,2) = ones(2)*2;
    mm(:,:,3) = ones(2)*3;
    mm(:,:,4) = ones(2)*4;
    
    dims = size(mm);
    mr = reshape(mm,dims(1)*dims(2),dims(3))'
    rm = reshape(mr,dims(2)*dims(3),dims(1))

This achieved the goal of putting the pixel bands together. However, it looks like a lot of work, and I have no idea what I'm doing to the computer memory.

Ideas for improvement welcomed.
Remember that the real image is much larger.

Thank you!

Subject: Seeking Best Hyperspectral-Image Reshaping (Planer to pixel

From: ImageAnalyst

Date: 15 May, 2009 16:44:21

Message: 2 of 6

"Pat Finder":
Would permute() help you? You probably have the 187 dimension as the
third one. With permute you could move it to the first one. I think
MATLAB has the leftmost index as the one with adjacent memory
locations (someone correct me if I'm wrong). However if you add the
time of rearranging your matrix to the analysis time, does that really
save any time over just analyzing it as-is? I guess you could just
try it (with tic and toc) and see.
Regards,
ImageAnalyst

Subject: Seeking Best Hyperspectral-Image Reshaping (Planer to pixel

From: Pat Finder

Date: 16 May, 2009 19:32:01

Message: 3 of 6

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <7ee29143-d401-4f58-8046-a008e0db0f33@s21g2000vbb.googlegroups.com>...
> "Pat Finder":
> Would permute() help you?

I guess what I'm looking for is someone who is familiar with the internals of the storage.

I am not familiar with permute. I will look into it, or if you could show me how to do it with the above simple example, I will try it with the full blown image.

- Pat

[P.S. my peers say "use IDL". :-(]

Subject: Seeking Best Hyperspectral-Image Reshaping (Planer to pixel

From: ImageAnalyst

Date: 16 May, 2009 20:45:06

Message: 4 of 6

On May 16, 3:32 pm, "Pat Finder" <pfin...@netacc.net> wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <7ee29143-d40=
1-4f58-8046-a008e0db0...@s21g2000vbb.googlegroups.com>...
> > "Pat Finder":
> > Would permute() help you?
>
> I guess what I'm looking for is someone who is familiar with the internal=
s of the storage.  
>
> I am not familiar with permute.  I will look into it, or if you could s=
how me how to do it with the above simple example, I will try it with the f=
ull blown image.
>
> - Pat
>
> [P.S. my peers say "use IDL".  :-(]

-------------------------------------------------------------------
I believe you'd use
Y = permute(X, [3 1 2]);

Subject: Seeking Best Hyperspectral-Image Reshaping (Planer to pixel

From: Ashish Uthama

Date: 27 May, 2009 13:59:17

Message: 5 of 6

On Fri, 15 May 2009 11:08:02 -0400, Pat Finder <pfinder@netacc.net> wrote:

> Questions:
> 1. Is there a better way?
> 2. Is there a faster way?
>
> I am working on a hyperspectral image that is 4096x512 by 187 bands.
>
> I'm doing classification, but it is very slow because every time I want
> to classify a pixel, I need to go to 187 places in memory.
>
> I am thinking that I need to reshape the image so that all the band data
> is right next to each other in memory, and then transpose it...
>
> Here is some simple code for a small matrix that shows what I think I
> need to do:
>
> mm = ones(2);
> mm(:,:,2) = ones(2)*2;
> mm(:,:,3) = ones(2)*3;
> mm(:,:,4) = ones(2)*4;
> dims = size(mm);
> mr = reshape(mm,dims(1)*dims(2),dims(3))'
> rm = reshape(mr,dims(2)*dims(3),dims(1))
>
> This achieved the goal of putting the pixel bands together. However, it
> looks like a lot of work, and I have no idea what I'm doing to the
> computer memory.
>
> Ideas for improvement welcomed.
> Remember that the real image is much larger.
>
> Thank you!


How are you loading this data into MATLAB? What format is the data in?
Could you perhaps read it in in such a way as to keep the pixels
interleaved?

Subject: Seeking Best Hyperspectral-Image Reshaping (Planer to pixel interleaved) for Speed

From: Chaos

Date: 27 May, 2009 22:05:03

Message: 6 of 6

"Pat Finder" <pfinder@netacc.net> wrote in message <guk0gi$3vl$1@fred.mathworks.com>...
> Questions:
> 1. Is there a better way?
> 2. Is there a faster way?
>
> I am working on a hyperspectral image that is 4096x512 by 187 bands.
>
> I'm doing classification, but it is very slow because every time I want to classify a pixel, I need to go to 187 places in memory.
>
> I am thinking that I need to reshape the image so that all the band data is right next to each other in memory, and then transpose it...
>
> Here is some simple code for a small matrix that shows what I think I need to do:
>
> mm = ones(2);
> mm(:,:,2) = ones(2)*2;
> mm(:,:,3) = ones(2)*3;
> mm(:,:,4) = ones(2)*4;
>
> dims = size(mm);
> mr = reshape(mm,dims(1)*dims(2),dims(3))'
> rm = reshape(mr,dims(2)*dims(3),dims(1))
>
> This achieved the goal of putting the pixel bands together. However, it looks like a lot of work, and I have no idea what I'm doing to the computer memory.
>
> Ideas for improvement welcomed.
> Remember that the real image is much larger.
>
> Thank you!

learn how to do PCA and/or Eigenvector analysis. Needing 187 bands for classification is amateurish and/or homework.

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