我正在尝试将 WLS 过滤器应用于从图像中获得的亮度层
print("Applying wls filter on base image")
face_structure_layer, skin_detail_layer = wls_filter.wlsfilter_layer(lightness_layer,cmat)
但是当我运行这个时,会抛出这个错误 [TypeError: order must be str, not int][1]
这是我正在使用的 WLS 过滤器的代码
import cv2
import sys
import numpy as np
import matplotlib.pyplot as plt
from scipy.sparse import spdiags
from scipy.sparse.linalg import spsolve
def wlsfilter_layer(image_orig, cmat, beta=0.2 ,lambda_=0.2):
image = image_orig.astype(np.float)/255.0
image1 = image.flatten()
s = image.shape()
k = np.prod(s)
gmat = cmat.copy()
for y in range(s[0]):
for x in range(s[1]):
if not gmat[y][x]==1:
gmat[y][x]=0
gmat = cv2.GaussianBlur(gmat,(5,5),0)
dy = np.diff(image, 1, 0)
dx = np.diff(image, 1, 1)
dy = -beta*lambda_ / ((np.absolute(dy) ** 1.2 + 0.0001))
dx = -beta*lambda_ / ((np.absolute(dx) ** 1.2 + 0.0001))
for y in range(s[0]-1):
for x in range(s[1]-1):
dy[y][x] = (gmat[y][x])*dy[y][x]
dx[y][x] = (gmat[y][x])*dx[y][x]
dy = np.vstack((dy, np.zeros(s[1], )))
dx = np.hstack((dx, np.zeros(s[0], )[:, np.newaxis]))
dy = dy.flatten(1)
dx = dx.flatten(1)
d = 1 - (dx + np.roll(dx, s[0]) + dy + np.roll(dy, 1))
a = spdiags(np.vstack((dx, dy)), [-s[0], -1], k, k)
a = a + a.T + spdiags(d, 0, k, k)
temp = spsolve(a, image1).reshape(s[::-1])
base = np.rollaxis(temp,1)
detail = image - base
return (base*255.0), (detail*255.0)
如果我单独运行 WLS 过滤器,它可以工作我使用不同类型的 np.flatten 检查,但它仍然抛出相同的错误 [1]:https ://i.stack.imgur.com/veAfo.jpg