stefanloock / pyshearlab

pyShearLab is a Python toolbox which is based on ShearLab3D written by Rafael Reisenhofer and has been ported to Python by Stefan Loock.
GNU General Public License v3.0
51 stars 18 forks source link

ValueError: setting an array element with a sequence #10

Open MaybeRichard opened 6 months ago

MaybeRichard commented 6 months ago

code:

    # Homemade version of matlab tic and toc functions
    import time
    global startTime_for_tictoc
    startTime_for_tictoc = time.time()

def toc():
    import time
    if 'startTime_for_tictoc' in globals():
        print("Elapsed time is " + str(time.time() - startTime_for_tictoc) + " seconds.")
    else:
        print("Toc: start time not set")

import numpy as np
from scipy import ndimage as img
from scipy import io as sio
import matplotlib.pyplot as plt
from imageio.v2 import imread
import pyshearlab

tic()
print("--SLExampleImageDenoising")
print("loading image...")

sigma = 30
scales = 3
thresholdingFactor = 3

# load data

X = imread("../dataset/train/noise/1.png")[::4, ::4]
X = X.astype(float)

# add noise
Xnoisy = X + sigma * np.random.randn(X.shape[0], X.shape[1])
toc()

tic()
print("generating shearlet system...")
## create shearlets
shearletSystem = pyshearlab.SLgetShearletSystem2D(0, X.shape[0], X.shape[1], scales)

toc()
tic()
print("decomposition, thresholding and reconstruction...")

# decomposition
coeffs = pyshearlab.SLsheardec2D(Xnoisy, shearletSystem)

# thresholding
oldCoeffs = coeffs.copy()
weights = np.ones(coeffs.shape)

for j in range(len(shearletSystem["RMS"])):
    weights[:, :, j] = shearletSystem["RMS"][j] * np.ones((X.shape[0], X.shape[1]))

coeffs = np.real(coeffs)
zero_indices = np.abs(coeffs) / (thresholdingFactor * weights * sigma) < 1
coeffs[zero_indices] = 0

# reconstruction
Xrec = pyshearlab.SLshearrec2D(coeffs, shearletSystem)
toc()
PSNR = pyshearlab.SLcomputePSNR(X, Xrec)
print("PSNR: " + str(PSNR))
# sio.savemat("PyShearLab_DenoisingExample.mat", {"weights": weights, "XPyNoisy": Xnoisy,
# "XPyDenoised": Xrec, "PyPSNR": PSNR, "coeffThrPy": coeffs, "oldCoeffs": oldCoeffs})
plt.gray()
plt.imshow(Xrec)
plt.colorbar()
plt.show()

Error:

loading image...
Elapsed time is 0.03148603439331055 seconds.
generating shearlet system...
Traceback (most recent call last):
  File "/Users/richardlee/Downloads/UNetDenoising/STV/Shearlet.py", line 43, in <module>
    shearletSystem = pyshearlab.SLgetShearletSystem2D(0, X.shape[0], X.shape[1], scales)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/torch/lib/python3.11/site-packages/pyshearlab/pyShearLab2D.py", line 157, in SLgetShearletSystem2D
    h0, h1 = dfilters('dmaxflat4', 'd')/np.sqrt(2)
             ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

I think may be something wrong with dfilters function

ien952129 commented 5 months ago

Have you found a way to solve it

waveajay commented 4 months ago

h0, h1 = dfilters('dmaxflat4', 'd') h0 = h0 / np.sqrt(2) h1 = h1 / np.sqrt(2) make above correction where ever something like h0, h1 = dfilters('dmaxflat4', 'd')/np.sqrt(2) or something similar is there

sheep1222 commented 3 months ago

h0, h1 = dfilters('dmaxflat4', 'd') h0 = h0 / np.sqrt(2) h1 = h1 / np.sqrt(2) make above correction where ever something like h0, h1 = dfilters('dmaxflat4', 'd')/np.sqrt(2) or something similar is there

Hello, do you know the meaning of the nScale parameter? I found that when there are the same shearLevels, nScale does not affect the decomposed result, so I am very confused about its function?