SkillAgentSearch skills...

Geotensor

Geometric low-rank tensor completion for color image inpainting.

Install / Use

/learn @xinychen/Geotensor
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

geotensor

MIT License Python 3.7 repo size GitHub stars

Motivation

  • Color image inpainting: Various missing patterns.
<table> <tr> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/lena_mar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/lena_mar.jpg?size=150" width="150px;" alt="Missing at random (MAR)"/><br /><sub><b>Missing at random (MAR)</b></sub></a><br /></td> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/lena_rmar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/lena_rmar.jpg?size=150" width="150px;" alt="Row-wise MAR"/><br /><sub><b>Row-wise MAR</b></sub></a><br /></td> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/lena_cmar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/lena_cmar.jpg?size=150" width="150px;" alt="Column-wise MAR"/><br /><sub><b>Column-wise MAR</b></sub></a><br /></td> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/lena_rcmar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/lena_rcmar.jpg?size=150" width="150px;" alt="(Row, column)-wise MAR"/><br /><sub><b>(Row, column)-wise MAR</b></sub></a><br /></td> </tr> </table>
  • Low-rank tensor completion: Characterizing images with graph (e.g., adjacent smoothness matrix based graph regularizer).

Implementation

One notable thing is that unlike the complex equations in our models, our Python implementation (relies on numpy) is extremely easy to work with. Take GLTC-Geman as an example, its kernel only has few lines:

def supergradient(s_hat, lambda0, theta):
    """Supergradient of the Geman function."""
    return (lambda0 * theta / (s_hat + theta) ** 2)

def GLTC_Geman(dense_tensor, sparse_tensor, alpha, beta, rho, theta, maxiter):
    """Main function of the GLTC-Geman."""
    dim0 = sparse_tensor.ndim
    dim1, dim2, dim3 = sparse_tensor.shape
    dim = np.array([dim1, dim2, dim3])
    binary_tensor = np.zeros((dim1, dim2, dim3))
    binary_tensor[np.where(sparse_tensor != 0)] = 1
    tensor_hat = sparse_tensor.copy()
    
    X = np.zeros((dim1, dim2, dim3, dim0)) # \boldsymbol{\mathcal{X}} (n1*n2*3*d)
    Z = np.zeros((dim1, dim2, dim3, dim0)) # \boldsymbol{\mathcal{Z}} (n1*n2*3*d)
    T = np.zeros((dim1, dim2, dim3, dim0)) # \boldsymbol{\mathcal{T}} (n1*n2*3*d)
    for k in range(dim0):
        X[:, :, :, k] = tensor_hat
        Z[:, :, :, k] = tensor_hat
    
    D1 = np.zeros((dim1 - 1, dim1)) # (n1-1)-by-n1 adjacent smoothness matrix
    for i in range(dim1 - 1):
        D1[i, i] = -1
        D1[i, i + 1] = 1
    D2 = np.zeros((dim2 - 1, dim2)) # (n2-1)-by-n2 adjacent smoothness matrix
    for i in range(dim2 - 1):
        D2[i, i] = -1
        D2[i, i + 1] = 1
        
    w = []
    for k in range(dim0):
        u, s, v = np.linalg.svd(ten2mat(Z[:, :, :, k], k), full_matrices = 0)
        w.append(np.zeros(len(s)))
        for i in range(len(np.where(s > 0)[0])):
            w[k][i] = supergradient(s[i], alpha, theta)

    for iters in range(maxiter):
        for k in range(dim0):
            u, s, v = np.linalg.svd(ten2mat(X[:, :, :, k] + T[:, :, :, k] / rho, k), full_matrices = 0)
            for i in range(len(np.where(w[k] > 0)[0])):
                s[i] = max(s[i] - w[k][i] / rho, 0)
            Z[:, :, :, k] = mat2ten(np.matmul(np.matmul(u, np.diag(s)), v), dim, k)
            var = ten2mat(rho * Z[:, :, :, k] - T[:, :, :, k], k)
            if k == 0:
                var0 = mat2ten(np.matmul(inv(beta * np.matmul(D1.T, D1) + rho * np.eye(dim1)), var), dim, k)
            elif k == 1:
                var0 = mat2ten(np.matmul(inv(beta * np.matmul(D2.T, D2) + rho * np.eye(dim2)), var), dim, k)
            else:
                var0 = Z[:, :, :, k] - T[:, :, :, k] / rho
            X[:, :, :, k] = np.multiply(1 - binary_tensor, var0) + sparse_tensor
            
            uz, sz, vz = np.linalg.svd(ten2mat(Z[:, :, :, k], k), full_matrices = 0)
            for i in range(len(np.where(sz > 0)[0])):
                w[k][i] = supergradient(sz[i], alpha, theta)
        tensor_hat = np.mean(X, axis = 3)
        for k in range(dim0):
            T[:, :, :, k] = T[:, :, :, k] + rho * (X[:, :, :, k] - Z[:, :, :, k])
            X[:, :, :, k] = tensor_hat.copy()

    return tensor_hat

Have fun if you work with our code!

<table> <tr> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/lena_mar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/lena_mar.jpg?size=150" width="150px;" alt="Missing at random (MAR)"/><br /><sub><b>Missing at random (MAR)</b></sub></a><br /></td> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/lena_rmar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/lena_rmar.jpg?size=150" width="150px;" alt="Row-wise MAR"/><br /><sub><b>Row-wise MAR</b></sub></a><br /></td> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/lena_cmar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/lena_cmar.jpg?size=150" width="150px;" alt="Column-wise MAR"/><br /><sub><b>Column-wise MAR</b></sub></a><br /></td> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/lena_rcmar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/lena_rcmar.jpg?size=150" width="150px;" alt="(Row, column)-wise MAR"/><br /><sub><b>(Row, column)-wise MAR</b></sub></a><br /></td> </tr> <tr> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/GLTC_Geman_lena_mar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/GLTC_Geman_lena_mar.jpg?size=150" width="150px;" alt="RSE = 6.74%"/><br /><sub><b>RSE = 6.74%</b></sub></a><br /></td> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/GLTC_Geman_lena_rmar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/GLTC_Geman_lena_rmar.jpg?size=150" width="150px;" alt="RSE = 8.20%"/><br /><sub><b>RSE = 8.20%</b></sub></a><br /></td> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/GLTC_Geman_lena_cmar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/GLTC_Geman_lena_cmar.jpg?size=150" width="150px;" alt="RSE = 10.80%"/><br /><sub><b>RSE = 10.80%</b></sub></a><br /></td> <td align="center"><a href="https://github.com/xinychen/geotensor/blob/master/data/GLTC_Geman_lena_rcmar.jpg"><img src="https://github.com/xinychen/geotensor/blob/master/data/GLTC_Geman_lena_rcmar.jpg?size=150" width="150px;" alt="RSE = 8.38%"/><br /><sub><b>RSE = 8.38%</b></sub></a><br /></td> </tr> </table>

Reference

  • General Matrix/Tensor Completion

| No | Title | Year | PDF | Code | |:---|:------|:----:|:---:|-----:| | 1 | Tensor Completion for Estimating Missing Values in Visual Data | 2013 | TPAMI | - | | 2 | Efficient tensor completion for color image and video recovery: Low-rank tensor train | 2016 | arxiv | - | | 3 | Tensor Robust Principal Component Analysis: Exact Recovery of Corrupted Low-Rank Tensors via Convex Optimization | 2016 | CVPR | Matlab | | 4 | Geometric Matrix Completion with Recurrent Multi-Graph Neural Networks | 2017 | NeurIPS| Python | | 5 | Efficient Low Rank Tensor Ring Completion | 2017 | ICCV | Matlab | | 6 | Spatio-Temporal Signal Recovery Based on Low Rank and Differential Smoothness | 2018 | IEEE | - | | 7 | Exact Low Tubal Rank Tensor Recovery from Gaussian Measurements | 2018 | IJCAI | Matlab | | 8 | Tensor Robust Principal Component Analysis with A New Tensor Nuclear Norm | 2018 | TPAMI | Matlab |

  • Singular Value Thresholding (SVT)

| No | Title | Year | PDF | Code | |:---|:------|:----:|:---:|-----:| | 1 | A General Iterative Shrinkage and Thresholding Algorithm for Non-convex Regularized Optim

Related Skills

View on GitHub
GitHub Stars45
CategoryDevelopment
Updated2mo ago
Forks14

Languages

Jupyter Notebook

Security Score

90/100

Audited on Jan 23, 2026

No findings