Exemplo n.º 1
0
    def get_psf(self, subpixel=True, tkhflt=False, tkhlmb=1e-3):
        """Get the estimated psf. If parameter `subpixel` is True, the
        subpixel resolution psf is returned, constructed by interpolation
        of the psf estimated at the resolution of the input image.
        """

        if subpixel:
            Hl = lanczos_filters((self.M, self.M), self.K,
                                 collapse_axes=False)
            gp = np.pad(self.g, ((0, self.img.shape[0] - self.gshp[0]),
                                 (0, self.img.shape[1] - self.gshp[1])),
                        'constant')
            grsp = fftconv(Hl, gp[..., np.newaxis, np.newaxis],
                           origin=(self.K, self.K),
                           axes=(0, 1),
                           )[0:self.gshp[0], 0:self.gshp[1]]
            shp = tuple(np.array(self.gshp) * self.M)
            gsub = np.transpose(grsp, (0, 2, 1, 3)).reshape(shp)
            gsub[gsub < 0.0] = 0.0
            if tkhflt:
                gsub, shp = tikhonov_filter(gsub, tkhlmb)
            gsub /= np.linalg.norm(gsub)
            return gsub
        else:
            return self.g / np.linalg.norm(self.g)
Exemplo n.º 2
0
"""
Load example image.
"""

img = util.ExampleImages().image('kodim23.png', scaled=True, gray=True,
                                 idxexp=np.s_[160:416,60:316])


"""
Highpass filter example image.
"""

npd = 16
fltlmbd = 10
sl, sh = signal.tikhonov_filter(img, fltlmbd, npd)


"""
Load dictionary and display it.
"""

D = util.convdicts()['G:12x12x36']
plot.imview(util.tiledict(D), fgsz=(7, 7))


"""
Set :class:`.admm.cbpdn.ConvBPDNProjL1` solver options.
"""

gamma = 4.05e2
Exemplo n.º 3
0
Load a reference image and corrupt it with Gaussian white noise with $\sigma = 0.1$. (The call to ``numpy.random.seed`` ensures that the pseudo-random noise is reproducible.)
"""

img = util.ExampleImages().image('monarch.png',
                                 zoom=0.5,
                                 scaled=True,
                                 idxexp=np.s_[:, 160:672])
np.random.seed(12345)
imgn = img + np.random.normal(0.0, 0.1, img.shape).astype(np.float32)
"""
Highpass filter test image.
"""

npd = 16
fltlmbd = 5.0
imgnl, imgnh = signal.tikhonov_filter(imgn, fltlmbd, npd)
"""
Load dictionary.
"""

D = util.convdicts()['G:8x8x128']
"""
Set solver options. See Section 8 of :cite:`wohlberg-2017-convolutional2` for details of construction of $\ell_1$ weighting matrix $W$.
"""

imgnpl, imgnph = signal.tikhonov_filter(pad(imgn), fltlmbd, npd)
W = fft.irfftn(
    np.conj(fft.rfftn(D[..., np.newaxis, :], imgnph.shape[0:2],
                      (0, 1))) * fft.rfftn(imgnph[..., np.newaxis], None,
                                           (0, 1)), imgnph.shape[0:2], (0, 1))
W = 1.0 / (np.maximum(np.abs(W), 1e-8))
Exemplo n.º 4
0
 def test_06(self):
     img = np.random.randn(16, 16, 16)
     iml, imh = signal.tikhonov_filter(img, 2.0, npd=8)
     assert iml.shape == img.shape and imh.shape == img.shape
Exemplo n.º 5
0
 def test_05(self):
     img = np.random.randn(64, 64)
     iml, imh = signal.tikhonov_filter(img, 5.0)
     assert iml.shape == img.shape and imh.shape == img.shape
Exemplo n.º 6
0
"""
Load example image.
"""

img = util.ExampleImages().image('kodim23.png', scaled=True,
                                 idxexp=np.s_[160:416,60:316])


"""
Highpass filter example image.
"""

npd = 16
fltlmbd = 10
slc, shc = signal.tikhonov_filter(img, fltlmbd, npd)


"""
Load greyscale convolutional dictionary.
"""

D = util.convdicts()['G:8x8x64']


"""
Learn a standard dictionary $B$ to represent all pixel colours in the example image. Since the standard dictionary is a $3 \times 6$ matrix, the sparse representation $X$ has 6 pseudo-channels, which are converted to the 3 channels of the example image by right-multiplication by the dictionary $B$, giving $XB$.
"""

S = shc.reshape((-1, shc.shape[-1])).T
np.random.seed(12345)
Exemplo n.º 7
0
 def test_07(self):
     img = np.random.randn(64, 64)
     iml, imh = signal.tikhonov_filter(img, 5.0)
     assert np.isrealobj(iml) and np.isrealobj(imh)
Exemplo n.º 8
0
 def test_06(self):
     img = np.random.randn(64, 64) + 1j * np.random.randn(64, 64)
     iml, imh = signal.tikhonov_filter(img, 5.0)
     assert np.iscomplexobj(iml) and np.iscomplexobj(imh)
Exemplo n.º 9
0
"""

reader = imageio.get_reader('imageio:cockatoo.mp4')
frmlst = []
for i, frm in enumerate(reader):
    if i >= 250:
        frm = zoom(signal.rgb2gray(frm.astype(np.float32) / 255.0), 0.25)
        frmlst.append(frm[20:-20, 70:-70])
vid = np.stack(frmlst, axis=2)
"""
Highpass filter video frames.
"""

npd = 16
fltlmbd = 10
vl, vh = signal.tikhonov_filter(vid, fltlmbd, npd)
"""
Construct initial dictionary.
"""

np.random.seed(12345)
D0 = np.random.randn(5, 5, 3, 25)
"""
Set regularization parameter and options for dictionary learning solver.
"""

lmbda = 0.1
opt = cbpdndl.ConvBPDNDictLearn.Options(
    {
        'Verbose': True,
        'MaxMainIter': 200,