From ddf7363edabae0cf958c4332a86fba96d0bb3a17 Mon Sep 17 00:00:00 2001 From: Colombo Date: Sat, 6 Jun 2020 20:02:21 +0400 Subject: [PATCH] remove unused code --- core/imagelib/__init__.py | 2 +- core/imagelib/color_transfer.py | 49 --------------------------------- 2 files changed, 1 insertion(+), 50 deletions(-) diff --git a/core/imagelib/__init__.py b/core/imagelib/__init__.py index 3ca92a2..4e8b83d 100644 --- a/core/imagelib/__init__.py +++ b/core/imagelib/__init__.py @@ -12,7 +12,7 @@ from .warp import gen_warp_params, warp_by_params from .reduce_colors import reduce_colors -from .color_transfer import color_transfer, color_transfer_mix, color_transfer_sot, color_transfer_mkl, color_transfer_idt, color_hist_match, reinhard_color_transfer, linear_color_transfer, seamless_clone +from .color_transfer import color_transfer, color_transfer_mix, color_transfer_sot, color_transfer_mkl, color_transfer_idt, color_hist_match, reinhard_color_transfer, linear_color_transfer from .common import normalize_channels, cut_odd_image, overlay_alpha_image diff --git a/core/imagelib/color_transfer.py b/core/imagelib/color_transfer.py index a329f7a..efc5a82 100644 --- a/core/imagelib/color_transfer.py +++ b/core/imagelib/color_transfer.py @@ -1,10 +1,7 @@ import cv2 import numpy as np from numpy import linalg as npla - import scipy as sp -import scipy.sparse -from scipy.sparse.linalg import spsolve def color_transfer_sot(src,trg, steps=10, batch_size=5, reg_sigmaXY=16.0, reg_sigmaV=5.0): """ @@ -134,52 +131,6 @@ def color_transfer_idt(i0, i1, bins=256, n_rot=20): return np.clip ( d0.T.reshape ( (h,w,c) ).astype(i0.dtype) , 0, 1) -def laplacian_matrix(n, m): - mat_D = scipy.sparse.lil_matrix((m, m)) - mat_D.setdiag(-1, -1) - mat_D.setdiag(4) - mat_D.setdiag(-1, 1) - mat_A = scipy.sparse.block_diag([mat_D] * n).tolil() - mat_A.setdiag(-1, 1*m) - mat_A.setdiag(-1, -1*m) - return mat_A - -def seamless_clone(source, target, mask): - h, w,c = target.shape - result = [] - - mat_A = laplacian_matrix(h, w) - laplacian = mat_A.tocsc() - - mask[0,:] = 1 - mask[-1,:] = 1 - mask[:,0] = 1 - mask[:,-1] = 1 - q = np.argwhere(mask==0) - - k = q[:,1]+q[:,0]*w - mat_A[k, k] = 1 - mat_A[k, k + 1] = 0 - mat_A[k, k - 1] = 0 - mat_A[k, k + w] = 0 - mat_A[k, k - w] = 0 - - mat_A = mat_A.tocsc() - mask_flat = mask.flatten() - for channel in range(c): - - source_flat = source[:, :, channel].flatten() - target_flat = target[:, :, channel].flatten() - - mat_b = laplacian.dot(source_flat)*0.75 - mat_b[mask_flat==0] = target_flat[mask_flat==0] - - x = spsolve(mat_A, mat_b).reshape((h, w)) - result.append (x) - - - return np.clip( np.dstack(result), 0, 1 ) - def reinhard_color_transfer(target, source, clip=False, preserve_paper=False, source_mask=None, target_mask=None): """ Transfers the color distribution from the source to the target