Util 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_ENVI_file¶
-
pysptools.util.
load_ENVI_file
(file_name)¶ 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_ENVI_spec_lib¶
-
pysptools.util.
load_ENVI_spec_lib
(file_name)¶ Load a ENVI .sli file.
- Parameters:
- file_name: path string
- The complete path to the library file to load.
- Returns: numpy array
A (n x p) HSI cube.
- head: dictionary
- Starting at version 0.13.1, the ENVI file header
corr¶
-
pysptools.util.
corr
(M)¶ Compute the sample autocorrelation matrix of a 2D matrix.
- Parameters:
- M: numpy array
- 2d matrix of HSI data (N x p)
- Returns: numpy array
- Sample autocorrelation matrix.
cov¶
-
pysptools.util.
cov
(M)¶ Compute the sample covariance matrix of a 2D matrix.
- Parameters:
- M: numpy array
- 2d matrix of HSI data (N x p)
- Returns: numpy array
- sample covariance matrix
display_linear_stretch¶
-
pysptools.util.
display_linear_stretch
(M, R, G, B, suffix=None)¶ 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_linear_stretch¶
-
pysptools.util.
plot_linear_stretch
(M, path, R, G, B, suffix=None)¶ 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.
convert2d¶
-
pysptools.util.
convert2d
(M)¶ Converts a 3D data cube (m x n x p) to a 2D matrix of points where N = m*n.
- Parameters:
- M: numpy array
- A HSI cube (m x n x p).
- Returns: numpy array
- 2D data matrix (N x p)
convert3d¶
-
pysptools.util.
convert3d
(N, h, w, sigLast=True)¶ 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¶
-
pysptools.util.
normalize
(M)¶ Normalizes M to be in range [0, 1].
- Parameters:
- M: numpy array
- 1D, 2D or 3D data.
- Returns: numpy array
- Normalized data.
ROIs¶
-
class
pysptools.util.
ROIs
(x, y)¶ Manage regions of interest (ROIs).
-
add
(id, *rois)¶ Add a named ROI.
- Parameters:
- id: string
- The class (or cluster) name.
- rois: dictionary list
- Each parameter, a dictionary, represent a rectangle or a polygon. They use matrix coordinates. 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 rectangle and/or polygon for a same cluster. The polygon and the rectangle must be well formed.
-
display
(colorMap='Accent', suffix=None)¶ 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_labels
()¶ Return a labels list.
- Return: list
- A labels list.
-
get_next
()¶ Iterator, return at each step: the cluster name and a ROI list.
- Return: tuple
- Cluster name, ROI list.
-
plot
(path, colorMap='Accent', suffix=None)¶ 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.
-