本文整理汇总了Python中pywt.idwt2函数的典型用法代码示例。如果您正苦于以下问题:Python idwt2函数的具体用法?Python idwt2怎么用?Python idwt2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了idwt2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _embed
def _embed(self):
container = EmbeddingMethodStack.rgb_2_ycbcr(self.container)
stego = numpy.copy(container)
self.watermark = skimage.color.rgb2gray(self.watermark)
self.watermark = scipy.misc.imresize(self.watermark, (numpy.divide(container.shape[0], 64),
numpy.divide(container.shape[1], 64)), interp='bicubic')
super(ElahianEmbedder, self)._embed()
watermark_bitstream = EmbeddingMethodStack.matrix_2_bitstream(self.watermark.astype(numpy.uint8))
position = EmbeddingMethodStack.pseudo_rand_mask_create(numpy.asarray((numpy.divide(container.shape[0], 8),
numpy.divide(container.shape[1], 8))))
self.aux[ElahianMethodConfig.AUX_POSITION] = position
c1a, (c1h, c1v, c1d) = pywt.dwt2(container[:, :, 0], self.aux[ElahianMethodConfig.AUX_WAVELET])
c2a, (c2h, c2v, c2d) = pywt.dwt2(c1a, self.aux[ElahianMethodConfig.AUX_WAVELET])
c3a, (c3h, c3v, c3d) = pywt.dwt2(c2a, self.aux[ElahianMethodConfig.AUX_WAVELET])
x = position[:, 1]
y = position[:, 0]
c3ae = numpy.copy(c3a)
# print c3ae.shape, watermark_bitstream.shape, position.shape
for k in range(watermark_bitstream.size - 1):
c3ae[y[k], x[k]] = c3a[y[k], x[k]] + self.aux[ElahianMethodConfig.AUX_G] * watermark_bitstream[k]
c2ae = pywt.idwt2((c3ae, (c3h, c3v, c3d)), self.aux[ElahianMethodConfig.AUX_WAVELET])
c1ae = pywt.idwt2((c2ae, (c2h, c2v, c2d)), self.aux[ElahianMethodConfig.AUX_WAVELET])
stego[:, :, 0] = pywt.idwt2((c1ae, (c1h, c1v, c1d)), self.aux[ElahianMethodConfig.AUX_WAVELET])
stego = EmbeddingMethodStack.ycbcr_2_rgb(stego, self.container.dtype)
# print stego.shape, self.watermark.shape, self.container.shape
return stego
示例2: test_idwt2_none_coeffs
def test_idwt2_none_coeffs():
data = np.array([[0, 1, 2, 3],
[1, 1, 1, 1],
[1, 4, 2, 8]])
data = data + 1j*data # test with complex data
cA, (cH, cV, cD) = pywt.dwt2(data, 'haar', axes=(1, 1))
# verify setting coefficients to None is the same as zeroing them
cD = np.zeros_like(cD)
result_zeros = pywt.idwt2((cA, (cH, cV, cD)), 'haar', axes=(1, 1))
cD = None
result_none = pywt.idwt2((cA, (cH, cV, cD)), 'haar', axes=(1, 1))
assert_equal(result_zeros, result_none)
示例3: recompose
def recompose(image, coarse, wtype):
print image.shape
# nothing to be done: case in which coarse is the size of image
if coarse.shape == image.shape:
return coarse
coeffs2 = pywt.dwt2(image,wtype,axes=(0,1))
if coeffs2[0].shape == coarse.shape:
ncoarse = coarse*2.0
elif coeffs2[0].shape[0] > coarse.shape[0] and coeffs2[0].shape[1] > coarse.shape[1]:
ncoarse = recompose(coeffs2[0],coarse*2.0,wtype)
else:
print "ERROR: Are you sure that \'%s\' is the right wavelet? Sizes don't match!"%wtype
print image.shape
print coarse.shape
exit()
#adjust size of upsampled version
isz = coeffs2[0].shape
ncoarse = ncoarse[0:isz[0],0:isz[1],:]
ncoeffs2 = (ncoarse, coeffs2[1])
ret = pywt.idwt2(ncoeffs2,wtype,axes=(0,1))
return ret
示例4: recompose
def recompose(prefix, levels, suffix, wtype, cur=0):
print prefix+str(cur)+suffix
image = piio.read(prefix+str(cur)+suffix)
print image.shape
if levels==1: # if last level
return image
LL = 2 * recompose(prefix,levels-1,suffix, wtype, cur+1) ## 2 compensates the factor used in decompose
coeffs2 = pywt.dwt2(image,wtype,axes=(0,1))
if coeffs2[0].shape != LL.shape:
print "ERROR: Are you sure that \'%s\' is the right wavelet? Sizes don't match!"%wtype
exit()
ncoeffs2 = (LL, coeffs2[1])
ret = pywt.idwt2(ncoeffs2,wtype, axes=(0,1))
# adjust size of the upsampled image
ret = ret[:image.shape[0],:image.shape[1],:]
print ret.shape
return ret
示例5: _embed
def _embed(self, img, payload, k):
cA, (cH, cV, cD) = dwt2(img, self.mother)
#assert cH2.shape == cV2.shape == cD2.shape
buffer = numpy.zeros(cH.size + cV.size + cD.size)
i = 0
for arr in (cH, cV, cD):
for row in arr:
buffer[i:i+row.size] = row
i += row.size
chunk_size = buffer.size // self.total_bits
sequence_of = (self.seq0[:chunk_size], self.seq1[:chunk_size])
for i, bit in enumerate(iterbits(payload)):
seq = sequence_of[bit]
buffer[i * chunk_size : i * chunk_size + seq.size] += k * seq
detail = (numpy.zeros(cH.shape), numpy.zeros(cV.shape), numpy.zeros(cD.shape))
i = 0
for arr in detail:
h, w = arr.shape
for r in range(h):
arr[r] = buffer[i:i+w]
i += w
h, w = img.shape
return idwt2((cA, detail), self.mother)[:h,:w]
示例6: _extract
def _extract(self):
c_a = numpy.zeros((numpy.divide(self.container.shape[0], 2),
numpy.divide(self.container.shape[1], 2), self.container.shape[2]),
dtype=numpy.single)
c_h = numpy.copy(c_a)
c_v = numpy.copy(c_a)
c_d = numpy.copy(c_a)
self.watermark = numpy.zeros(self.aux[EmbeddingMethodConfig.AUX_STEGO_SIZE], dtype=self.container.dtype)
for i in range(self.container.ndim):
c_a[:, :, i], (c_h[:, :, i], c_v[:, :, i], c_d[:, :, i]) = pywt.dwt2(self.container[:, :, i],
self.aux[DeyMethodConfig.AUX_WAVELET])
caw, (chw, cvw, cdw) = pywt.dwt2(self.stego[:, :, i], self.aux[DeyMethodConfig.AUX_WAVELET])
cas = (caw - (1 - self.aux[DeyMethodConfig.AUX_G]) * c_a[:, :, i]) / self.aux[DeyMethodConfig.AUX_G]
chs = (chw - (1 - self.aux[DeyMethodConfig.AUX_G]) * c_h[:, :, i]) / self.aux[DeyMethodConfig.AUX_G]
cvs = (cvw - (1 - self.aux[DeyMethodConfig.AUX_G]) * c_v[:, :, i]) / self.aux[DeyMethodConfig.AUX_G]
cds = (cdw - (1 - self.aux[DeyMethodConfig.AUX_G]) * c_d[:, :, i]) / self.aux[DeyMethodConfig.AUX_G]
size = cas.shape[0] / 2
LL = (cas[0:size, 0:size] + chs[0:size, 0:size] + cvs[0:size, 0:size] + cds[0:size, 0:size]) / 4
LH = (cas[size:2 * size, 0:size] + chs[size:2 * size, 0:size] + cvs[size:2 * size, 0:size] + cds[
size:2 * size,
0:size]) / 4
HL = (cas[0:size, size:2 * size] + chs[0:size, size:2 * size] +
cvs[0:size, size:2 * size] + cds[0:size, size:2 * size]) / 4
HH = (cas[size:2 * size, size:2 * size] + chs[size:2 * size, size:2 * size] +
cvs[size:2 * size, size:2 * size] + cds[size:2 * size, size:2 * size]) / 4
self.watermark[:, :, i] = pywt.idwt2((LL, (LH, HL, HH)), self.aux[DeyMethodConfig.AUX_WAVELET])
super(DeyExtractor, self)._extract()
return self.watermark
示例7: test_per_axis_wavelets_and_modes
def test_per_axis_wavelets_and_modes():
# tests seperate wavelet and edge mode for each axis.
rstate = np.random.RandomState(1234)
data = rstate.randn(16, 16, 16)
# wavelet can be a string or wavelet object
wavelets = (pywt.Wavelet('haar'), 'sym2', 'db4')
# mode can be a string or a Modes enum
modes = ('symmetric', 'periodization',
pywt._extensions._pywt.Modes.reflect)
coefs = pywt.dwtn(data, wavelets, modes)
assert_allclose(pywt.idwtn(coefs, wavelets, modes), data, atol=1e-14)
coefs = pywt.dwtn(data, wavelets[:1], modes)
assert_allclose(pywt.idwtn(coefs, wavelets[:1], modes), data, atol=1e-14)
coefs = pywt.dwtn(data, wavelets, modes[:1])
assert_allclose(pywt.idwtn(coefs, wavelets, modes[:1]), data, atol=1e-14)
# length of wavelets or modes doesn't match the length of axes
assert_raises(ValueError, pywt.dwtn, data, wavelets[:2])
assert_raises(ValueError, pywt.dwtn, data, wavelets, mode=modes[:2])
assert_raises(ValueError, pywt.idwtn, coefs, wavelets[:2])
assert_raises(ValueError, pywt.idwtn, coefs, wavelets, mode=modes[:2])
# dwt2/idwt2 also support per-axis wavelets/modes
data2 = data[..., 0]
coefs2 = pywt.dwt2(data2, wavelets[:2], modes[:2])
assert_allclose(pywt.idwt2(coefs2, wavelets[:2], modes[:2]), data2,
atol=1e-14)
示例8: _embed
def _embed(self, img, payload, k):
rand = Random(self.seed)
cA, (cH, cV, cD) = dwt2(img, self.mother)
cD2 = cD.reshape(cD.size)
for bit in iterbits(payload):
seq = numpy.array([int(rand.random() > 0.95) for _ in range(cD2.size)])
if bit:
cD2 += k * seq
return idwt2((cA, (cH, cV, cD2.reshape(cD.shape))), self.mother)[:img.shape[0],:img.shape[1]]
示例9: inversa
def inversa(coefficientes,escala):#Funcion para recuperar original
inv=pywt.idwt2(coefficientes,'haar')#Funcion inversa
pixeles=escala.load()
ancho,alto=escala.size
for i in range(ancho):
for j in range(alto):
nuevo=int(inv[i,j])
pixeles[i,j]=(nuevo,nuevo,nuevo)
return escala
示例10: build_im
def build_im(decoded_data, height, width, wavelet, q):
LL = (np.cumsum(np.array(decoded_data[0:int(height/2 * width/2)]))).reshape(height/2, width/2)
LH = (np.array(decoded_data[int(height/2 * width/2):2*int(height/2 * width/2)])*q).reshape(height/2, width/2)
HL = (np.array(decoded_data[2*int(height/2 * width/2):3*int(height/2 * width/2)])*q).reshape(height/2, width/2)
HH = (np.array(decoded_data[3*int(height/2 * width/2):4*int(height/2 * width/2)])*q).reshape(height/2, width/2)
im = pywt.idwt2( (LL, (LH, HL, HH)), wavelet,mode='periodization' )
show(im)
return im
示例11: _recreate16
def _recreate16(self, subbands, wavelet):
"""
Recreate the original from the 16 subbands.
Parameters
----------
subbands : list of 16 numpy arrays giving the subbands
wavelet : string, giving the pywavelets name of the wavelet to use
Returns
-------
img : numpy array, inverting the effect of _decompose16
"""
LL = pywt.idwt2((subbands[0], tuple(subbands[1:4])), wavelet, mode='per')
details = []
for i in xrange(1,4):
details.append(pywt.idwt2((subbands[4*i], tuple(subbands[4*i+1:4*i+4])), wavelet, mode='per'))
return pywt.idwt2((LL, tuple(details)), wavelet, mode='per')
示例12: test_ignore_invalid_keys
def test_ignore_invalid_keys():
data = np.array([[0, 4, 1, 5, 1, 4], [0, 5, 6, 3, 2, 1], [2, 5, 19, 4, 19, 1]])
wavelet = pywt.Wavelet("haar")
LL, (HL, LH, HH) = pywt.dwt2(data, wavelet)
d = {"aa": LL, "da": HL, "ad": LH, "dd": HH, "foo": LH, "a": HH}
assert_allclose(pywt.idwt2((LL, (HL, LH, HH)), wavelet), pywt.idwtn(d, wavelet), atol=1e-15)
示例13: test_idwt2_axes
def test_idwt2_axes():
data = np.array([[0, 1, 2, 3],
[1, 1, 1, 1],
[1, 4, 2, 8]])
coefs = pywt.dwt2(data, 'haar', axes=(1, 1))
assert_allclose(pywt.idwt2(coefs, 'haar', axes=(1, 1)), data, atol=1e-14)
# too many axes
assert_raises(ValueError, pywt.idwt2, coefs, 'haar', axes=(0, 1, 1))
示例14: main
def main():
#quantization factor. Might change
try:
input_file_name = sys.argv[1]
print "Attempting to open %s..." % input_file_name
input_file = open(sys.argv[1], 'rb')
except:
print "Unable to open input file. Qutting."
quit()
try:
output_file_name = sys.argv[2]
print "Attempting to open %s..." % output_file_name
output_file = open(sys.argv[2], 'wb')
except:
print "Unable to open output file. Qutting."
quit()
header = json.loads(input_file.readline())
code_dict = json.loads(input_file.readline())
print header
height = int(header['height'])
width = int(header['width'])
wavelet = header['wavelet']
q = int(header['q'])
decode_dict = {v.encode() : k for k, v in code_dict.iteritems()}
binary_data = input_file.read()
binary_string = ""
for byte in binary_data:
binary_string += format(ord(byte),'08b')
decdoed_data = []
while len(decdoed_data) != 4*(0.5*height * 0.5*width):
sub_str = ""
i = 0
while sub_str not in decode_dict:
sub_str = binary_string[0:i]
i=i+1
decdoed_data += [int(decode_dict[sub_str])]
binary_string = binary_string[i-1:]
print height, width
print decdoed_data
LL = (np.cumsum(np.array(decdoed_data[0:int(height/2 * width/2)]))).reshape(height/2, width/2)
LH = (np.array(decdoed_data[int(height/2 * width/2):2*int(height/2 * width/2)])*q).reshape(height/2, width/2)
HL = (np.array(decdoed_data[2*int(height/2 * width/2):3*int(height/2 * width/2)])*q).reshape(height/2, width/2)
HH = (np.array(decdoed_data[3*int(height/2 * width/2):4*int(height/2 * width/2)])*q).reshape(height/2, width/2)
show(LL)
im = pywt.idwt2( (LL, (LH, HL, HH)), wavelet,mode='periodization' )
show(im)
scipy.misc.toimage(im).save(output_file)
示例15: dwtfft
def dwtfft(data, level=6, wname='db10', sigma=2):
""" Remove ring artifacts.
Parameters
----------
data : ndarray
Input stack of projections.
level : scalar, optional
Number of DWT levels.
wname : str, optional
Type of the wavelet filter.
sigma : scalar, optional
Damping parameter in Fourier space.
References
----------
- Optics Express, Vol 17(10), 8567-8591(2009)
"""
for n in range(data.shape[1]):
# Wavelet decomposition.
im = data[:, n, :]
cH = []
cV = []
cD = []
for m in range(level):
im, (cHt, cVt, cDt) = pywt.dwt2(im, wname)
cH.append(cHt)
cV.append(cVt)
cD.append(cDt)
# FFT transform of horizontal frequency bands.
for m in range(level):
# FFT
fcV = np.fft.fftshift(np.fft.fft(cV[m], axis=0))
my, mx = fcV.shape
# Damping of ring artifact information.
y_hat = (np.arange(-my, my, 2, dtype='float')+1) / 2
damp = 1 - np.exp(-np.power(y_hat, 2) / (2 * np.power(sigma, 2)))
fcV = np.multiply(fcV, np.transpose(np.tile(damp, (mx, 1))))
# Inverse FFT.
cV[m] = np.real(np.fft.ifft(np.fft.ifftshift(fcV), axis=0))
# Wavelet reconstruction.
nim = im
for m in range(level)[::-1]:
nim = nim[0:cH[m].shape[0], 0:cH[m].shape[1]]
nim = pywt.idwt2((nim, (cH[m], cV[m], cD[m])), wname)
nim = nim[0:data.shape[0], 0:data.shape[2]]
data[:, n, :] = nim
return data