TypeError: order must be str, not int in np.flatten()

415 views Asked by At

I'm trying to apply a WLS filter to a lightness layer I obtained from my image

print("Applying wls filter on base image")
face_structure_layer, skin_detail_layer = wls_filter.wlsfilter_layer(lightness_layer,cmat)

But when I run this, this error is thrown [TypeError: order must be str, not int][1]

Here is the code for the WLS filter I'm using

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)

if I run the WLS filter separately it works I checked using np.flatten with different types but it still throws the same error [1]: https://i.stack.imgur.com/veAfo.jpg

0

There are 0 answers