colourlab.image module¶
image: Colour image, part of the colourlab package
Copyright (C) 2017-2021 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.
-
anisotropic_diffusion(sp, nit, dpsi_dlambda1=None, dpsi_dlambda2=None, dt=0.25, linear=True, g_func=None, constraint=None)[source]¶ Compute the anisotropic diffusion of the image.
Parameters: - sp (space.Space) – The colour space in which to perform the diffusion
- nit (int) – Number of iterations
- dpsi_dlambda1 (func) – The diffusion supression function for the first eigenvalue of the structure tensor. If None, use Perona and Malik’s inverse square with kappa = 1e-2.
- dpsi_dlambda2 (func) – Same for the second eigenvalue. If None use dpsi_dlambda1
- linear (bool) – Linear anisotropic diffusion if true
- g_func (func) – Function computing the metric tensor to use. If not given, uses Euclidean in the given space
- constraint (func) – Function returning the constrained image (e.g., gamut or internal boundaries, e.g. CFAs or fixed domains for inpainting) in sp
Returns: space.Image
Return type: the resulting anisotropically diffused image
-
c2g_diffusion(sp, nit, g_func=None, l_minus=True, scale=1, dt=0.25, dpsi_dlambda1=None, dpsi_dlambda2=None)[source]¶ Convert colour image to greyscale using linear 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
- dpsi_dlambda1 (func) – The diffusion supression function for the first eigenvalue of the structure tensor. If None, use Perona and Malik’s inverse square with kappa = 1e-2.
- dpsi_dlambda2 (func) – Same for the second eigenvalue. If None use dpsi_dlambda1
Returns: grey_image – Greyscale image (range 0–1)
Return type: ndarray
-
diffusion_tensor(sp, dpsi_dlambda1=None, dpsi_dlambda2=None, g_func=None, diff=(array([[ 0. , -0.5, 0. ], [ 0. , 0. , 0. ], [ 0. , 0.5, 0. ]]), array([[ 0. , 0. , 0. ], [-0.5, 0. , 0.5], [ 0. , 0. , 0. ]])), 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 ———-100100 sp : Space
The space in which to perform the computations- dpsi_dlambda1 : func
- The diffusion supression function for the first eigenvalue of the structure tensor. If None, use Perona and Malik’s inverse square with kappa = 1e-2.
- dpsi_dlambda2 : func
- Same for the second eigenvalue. If None use dpsi_dlambda1
- g_func : func
- Function computing the metric tensor to use. If not given, uses Euclidean in the given space
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.
-
gradient(sp, diff=(array([[ 0. , -0.5, 0. ], [ 0. , 0. , 0. ], [ 0. , 0.5, 0. ]]), array([[ 0. , 0. , 0. ], [-0.5, 0. , 0.5], [ 0. , 0. , 0. ]])))[source]¶ Compute the gradient components in the given colour space
Parameters: - sp (colour.space.Space) – The colour space
- diff (tuple) – Tuple with the two filters for the derivatives. Defaults to centered differences
Returns: - image.data.Vector (The i component of the gradient as a colour vector)
- image.data.Vector (The j component of the gradient as a colour vector)
-
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_func=None, diff=(array([[ 0. , -0.5, 0. ], [ 0. , 0. , 0. ], [ 0. , 0.5, 0. ]]), array([[ 0. , 0. , 0. ], [-0.5, 0. , 0.5], [ 0. , 0. , 0. ]])), 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_func (func) – Function computing the metric tensor to use. If not given, uses Euclidean in the given space
- diff (tuple) – Tuple with the two filters for the derivatives. Defaults to centered differences
- 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
-