#
##### Page tree
Go to start of banner

# Manipulation of HS Data in Matlab

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

### Import and export of HS data into and from Matlab

Import the cube with the following command:

`[C,p,u] = LoadHSData;`

Save a cube with the following command:

`SaveHSData(C,p,u);`

Please see detailed information about file import and export possibilities in the File Import / Export documentation.

### Code snippet on primitive data manipulation

#### Concatenate cubes

```[C1 p u] = LoadHSData;	%load cube C1 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]);
C_=zeros(size(C));
for i=1:size(C,3)
C_(:,:,i) = rot90(C(:,:,i));
end
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
```

© 2019 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, Wartingergasse 42, A-8010 Graz; Austria; FN 400381x

• No labels