Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

This page summarizes some code snippets on manipulation of HS cubes in Matlab.


Import and export of HS data into and from Matlab

Download LoadHSData Matlab function from here and save it in your Matlab user directory.
Import the cube by the following command:

[C,p,u] = LoadHSData;

Download SaveHSData Matlab function from here and save it in your Matlab user directory.
Save a cube by the following command:


Please see detailed information about file import and export possibilities here.

Code snippet on primitive data manipulation

Concatenate cubes

[C1 p u] = LoadHSData;	%load cube C1 from file
[C2 p u] = LoadHSData;	%load cube C2 from file

%concatenate cubes along sample direction
C3 = cat(3,C1,C2);		

%concatenate cubes along spatial direction
C3 = cat(1,C1,C2);		

SaveHSData(C3,p,u);		%save resulting cube C3 to file

Rotate cube

[C p u] = LoadHSData;	%load cube C from file

%rotate cube in the pixel domain about 90 degree
C=permute(C,[1 3 2]);
for i=1:size(C,3)
	C_(:,:,i) = rot90(C(:,:,i));
C=permute(C_,[1 3 2]);

SaveHSData(C,p,u);		%save rotated cube C to file

Crop cube

[C p u] = LoadHSData;	%load cube C from file

%crop out a cube of size 11x11x11 beginning at spatial position 10, spectral position 10 and sample position 10
%Note: size of cube must match! - should be greater or equal to 20x20x20 in this example
ivROISpat = [10 20];		
ivROISpec = [10 20];		
ivROISamp = [10 20];	
C = C( ivROISpat(1):ivROISpat(2) ,...
       ivROISpec(1):ivROISpec(2) ,...
 	   ivROISamp(1):ivROISamp(2) );

SaveHSData(C,p,u);		%save cropped cube C to file

Sub sample cube

[C p u] = LoadHSData;	%load cube C from file

%subsample each direction of cube C about factor 2
ivROISpat = 1:2:size(C,1);		
ivROISpec = 1:2:size(C,2);
ivROISamp = 1:2:size(C,3);
C = C( ivROISpat ,...
       ivROISpec ,...
 	   ivROISamp );

SaveHSData(C,p,u);		%save sub sampled cube C to file


© 2016 by Perception Park GmbH
The content of this page and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact Perception Park and delete copied material. Perception Park GmbH, Nikolaiplatz 4 / 3, A-8020 Graz; Austria; FN 400381x

  • No labels