Utility Functions and Classes¶
The load_ENVI_file and load_ENVI_spec_lib functions are used by the examples to load the HS cubes that are saved in the ENVI file format. The functions corr and cov are the one defined in the Matlab Hyperspectral Toolbox.
Load the data and the header from an ENVI file¶
-
pysptools.util.
load_ENVI_file
(file_name)[source]¶ Load the data and the header from an ENVI file. It use the SPy (spectral) library. At ‘file_name’ give the envi header file name.
Parameters: file_name – path string The complete path to the file to load. Use the header file name. - Returns: tuple
- data: numpy array
- A (m x n x p) HSI cube.
- head: dictionary
- Starting at version 0.13.1, the ENVI file header
Load an ENVI.sli file¶
Autocorrelation¶
Covariance¶
Display a linear stretched RGB image¶
-
pysptools.util.
display_linear_stretch
(M, R, G, B, suffix=None)[source]¶ Display a linear stretched RGB image.
Parameters: - M – numpy array A HSI cube (m x n x p).
- R – int A band number that will render the red color.
- G – int A band number that will render the green color.
- B – int A band number that will render the blue color.
- suffix – string [default None] Add a suffix to the title.
Plot a linear stretched RGB image¶
-
pysptools.util.
plot_linear_stretch
(M, path, R, G, B, suffix=None)[source]¶ Plot a linear stretched RGB image.
Parameters: - M – numpy array A HSI cube (m x n x p).
- path – string The path where to put the plot.
- R – int A band number that will render the red color.
- G – int A band number that will render the green color.
- B – int A band number that will render the blue color.
- suffix – string [default None] Add a suffix to the file name.
Converts a 3D data cube to a 2D matrix¶
Converts a 1D or 2D matrix to a 3D data cube¶
-
pysptools.util.
convert3d
(M, h, w, sigLast=True)[source]¶ Converts a 1D (N) or 2D matrix (p x N) or (N x p) to a 3D data cube (m x n x p) where N = m * n
Parameters: - N – numpy array 1D (N) or 2D data matrix (p x N) or (N x p)
- h – integer Height axis length (or y axis) of the cube.
- w – integer Width axis length (or x axis) of the cube.
- siglast – True [default False] Determine if input N is (p x N) or (N x p).
- Returns: numpy array
- A 3D data cube (m x n x p)
Normalize¶
Manage Regions of Interests¶
-
class
pysptools.util.
ROIs
(x, y)[source]¶ Manage regions of interest (ROIs).
-
add
(id, *rois)[source]¶ Add a named ROI.
Parameters: - id – string The class (or cluster) name.
- rois – dictionary list Each parameter, a dictionary, represent a rectangle, a polygon or a raw array. They use matrix coordinates. For a raw array: {‘raw’: mask-array}, mask-array is a binary 2D array with the hypercube (x,y) dimensions. For a rectangle: {‘rec’: (upper_left_line, upper_left_column, lower_right_line, lower_right_column)}. For a polygone: {‘poly’: ((l1,c1),(l2,c2), …)}, l stand for line and c for column. The polygon don’t need to be close. You can define one or more raw, rectangle and/or polygon for a same cluster. The polygon and the rectangle must be well formed.
-
display
(colorMap='Accent', suffix=None)[source]¶ Display the ROIs.
Parameters: - colorMap – string [default ‘Accent’] A color map element of [‘Accent’, ‘Dark2’, ‘Paired’, ‘Pastel1’, ‘Pastel2’, ‘Set1’, ‘Set2’, ‘Set3’], “Accent” is the default and it fall back on “Jet”.
- suffix – string [default None] Add a suffix to the file name.
-
get_next
()[source]¶ Iterator, return at each step: the cluster name and a ROI list.
- Return: tuple
- Cluster name, ROI list.
-
plot
(path, colorMap='Accent', suffix=None)[source]¶ Plot the ROIs.
Parameters: - path – string The path where to put the plot.
- colorMap – string [default ‘Accent’] A color map element of [‘Accent’, ‘Dark2’, ‘Paired’, ‘Pastel1’, ‘Pastel2’, ‘Set1’, ‘Set2’, ‘Set3’], “Accent” is the default and it fall back on “Jet”.
- suffix – string [default None] Add a suffix to the file name.
-