Пример #1
0
from builtins import range

import numpy as np

from sporco import util
from sporco import plot
from sporco.admm import tvl1


# Load reference image
img = util.ExampleImages().image('lena', scaled=True)


# Construct test image
np.random.seed(12345)
imgn = util.spnoise(img, 0.2)


# Set up TVL1Denoise options
lmbda = 8e-1
opt = tvl1.TVL1Denoise.Options({'Verbose' : True, 'MaxMainIter' : 200,
                                'RelStopTol' : 1e-3, 'gEvalY' : False})


# Initialise and run TVL1Denoise object
b = tvl1.TVL1Denoise(imgn, lmbda, opt, caxis=2)
imgr = b.solve()
print("TVL1Denoise solve time: %.2fs" % b.runtime)


# Display test images
Пример #2
0
 def test_06(self):
     img = np.random.randn(64, 64)
     imgn = util.spnoise(img, 0.5)
Пример #3
0
"""

pth = os.path.join(tempfile.gettempdir(), 'Indian_pines.mat')
if not os.path.isfile(pth):
    url = 'http://www.ehu.eus/ccwintco/uploads/2/22/Indian_pines.mat'
    vid = util.netgetdata(url)
    f = open(pth, 'wb')
    f.write(vid.read())
    f.close()

img = sio.loadmat(pth)['indian_pines'].astype(np.float32)
img = img[16:-17, 16:-17, 0:200:2]
img /= img.max()

np.random.seed(12345)
imgn = util.spnoise(img, 0.33)


"""
We use a product dictionary :cite:`garcia-2018-convolutional2` constructed from a single-channel convolutional dictionary for the spatial axes of the image, and a standard (non-convolutional) dictionary for the spectral axis of the image. The impulse denoising problem is solved by appending an additional filter to the learned dictionary ``D0``, which is one of those distributed with SPORCO. This additional component consist of an impulse filters that will represent the low frequency image components when used together with a gradient penalty on the coefficient maps, as discussed below. The spectral axis dictionary is learned from the noise-free ground-truth image since the primary purpose of this script is as a code usage example: in a real application, this dictionary would be estimated from a relevant noise-free image.
"""

D0 = util.convdicts()['G:8x8x32']
Di = np.zeros(D0.shape[0:2] + (1,), dtype=np.float32)
Di[0, 0] = 1.0
D = np.concatenate((Di, D0), axis=2)

S = img.reshape((-1, img.shape[-1])).T
np.random.seed(12345)
B0 = np.random.randn(S.shape[0], 20)
lmbda = 0.02
Пример #4
0
                        mode='constant')
crop = lambda x: x[n + n2:-n + n2, n + n2:-n + n2]
conv = lambda h, x: np.fft.ifft2(np.fft.fft2(h, x.shape) * np.fft.fft2(x)).real

# Load reference image
img = util.ExampleImages().image('lena.grey', scaled=True)

# Construct smoothing filter
h0 = np.zeros((13, 13), dtype=np.float32)
h0[6, 6] = 1.0
h = ndimage.filters.gaussian_filter(h0, 2.0)

# Construct test image
imgc = crop(conv(h, spad(img)))
np.random.seed(12345)
imgcn = util.spnoise(imgc, 0.2)

# Set up TVDeconv options
lmbda = 1e-2
wdf = np.ones(imgcn.shape)
opt = tvl1.TVL1Deconv.Options({
    'Verbose': True,
    'MaxMainIter': 200,
    'rho': 2e0,
    'gEvalY': False,
    'DFidWeight': zpad(wdf)
})

# Initialise and run TVL1Deconv object
b = tvl1.TVL1Deconv(h, spad(imgcn), lmbda, opt)
imgr = b.solve()[n - n2:-n - n2, n - n2:-n - n2]
import numpy as np
from sporco.util import spnoise

img = np.zeros([64, 64], dtype='uint8') + 128
img = spnoise(img, 0.1, 0, 255)
print(type(img[0][0]))
Пример #6
0
 def test_09(self):
     img = np.random.randn(64, 64)
     imgn = util.spnoise(img, 0.5)
def polute_img(pil_img, noise_lv):
    np_img = np.array(pil_img)
    np_img = util.spnoise(np_img, noise_lv, 0, 255)
    return Image.fromarray(np_img)