colourlab.image module¶
image: Colour image, part of the colourlab package
Copyright (C) 2017 Ivar Farup
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
-
class
colourlab.image.Image(sp, ndata)[source]¶ Bases:
colourlab.data.PointsSubclass of data.Points specifically for image shaped data.
-
c2g_diffusion(sp, nit, g=None, l_minus=True, scale=1, dt=0.25, aniso=True, param=0.0001, type='invsq')[source]¶ Convert colour image to greyscale using anisotropic diffusion
Parameters: - sp (Space) – Colour space in which to perform the numerical computations
- nit (int) – Number of iterations to compute
- g (Tensors) – The colour metric tensor. If not given, use Euclidean
- l_minus (bool) – Use lambda_minus in the computation of the gradient
- scale (float) – Distance from black to white according to metric
- dt (float) – Time step
- param (float) – The parameter for the nonlinear diffusion function
- type (str) – The type of diffusion function, invsq (inverse square) or exp (exponential), see Perona and Malik (1990)
Returns: grey_image – Greyscale image (range 0–1)
Return type: ndarray
-
diffusion_tensor(sp, param=0.0001, g=None, type='invsq', dir='p', grey=None)[source]¶ Compute the diffusion tensor coefficients for the image point set
Assumes (for now) that the underlying data constitutes an image, i.e., is on the shape M x N x 3.
Parameters: - sp (Space) – The space in which to perform the computations
- param (float) – The parameter for the nonlinear diffusion function
- g (Tensors) – The colour metric tensor. If not given, use Euclidean
- type (str) – The type of diffusion function, invsq (inverse square) or exp (exponential), see Perona and Malik (1990)
- dir (str) – The direction for the finite differences, p (plus), m (minus), c (centered)
Returns: - d11 (ndarray) – The d11 component of the structure tensor of the image data.
- d12 (ndarray) – The d12 component of the structure tensor of the image data.
- d22 (ndarray) – The d22 component of the structure tensor of the image data.
-
diffusion_tensor_from_structure(s_tuple, param=0.0001, type='invsq')[source]¶ Compute the diffusion tensor coefficients from the structure tensor parameters
Parameters: - s_tuple (tuple) – The resulting tuple from a call to self.structure_tensor
- param (float) – The parameter for the nonlinear diffusion function
- type (str) – The type of diffusion function, invsq (inverse square) or exp (exponential), see Perona and Malik (1990)
Returns: - d11 (ndarray) – The d11 component of the structure tensor of the image data.
- d12 (ndarray) – The d12 component of the structure tensor of the image data.
- d22 (ndarray) – The d22 component of the structure tensor of the image data.
-
stress(sp_in, sp_out=None, ns=3, nit=5, R=0)[source]¶ Compute STRESS in the given colour space.
Parameters: - sp_in (space.Space) – The input colour space.
- sp_out (space.Space) – The colour space for the interpretation of the result. If None, it is taken to be the same as sp_in.
- ns (int) – Number of sample points.
- nit (int) – Number of iterations.
- R (int) – Radius in pixels. If R=0, the diagonal of the image is used.
Returns: The resulting STRESS image.
Return type:
-
structure_tensor(sp, g=None, dir='p', grey=None)[source]¶ Return the structure tensor of the underlying data image point set
Assumes (for now) that the underlying data constitutes an image, i.e., is on the shape M x N x 3. Note that the returned eigenvectors are not oriented in a particular way (+- pi).
Parameters: - sp (Space) – The space in which to perform the computations
- g (Tensors) – The metric tensor to use. If not given, uses Euclidean in the current space
- dir (str) – The direction for the finite differences, p (plus), m (minus), c (centered)
- grey (ndarray Grey scale image for orientation of lightness) – gradient. If not present, use CIELAB L* channel
Returns: - s11 (ndarray) – The s11 component of the structure tensor of the image data.
- s12 (ndarray) – The s12 component of the structure tensor of the image data.
- s22 (ndarray) – The s22 component of the structure tensor of the image data.
- lambda1 (ndarray) – The first eigenvalue of the structure tensor
- lambda2 (ndarray) – The second eigenvalue of the structure tensor
- e1i (ndarray) – The first component of the first eigenvector
- e1j (ndarray) – The second component of the first eigenvector
- e2i (ndarray) – The first component of the second eigenvector
- e2j (ndarray) – The second component of the second eigenvector
-