In [1]:
import cv2
In [2]:
import urllib.request
In [3]:
import numpy as np
In [4]:
import glymur
In [5]:
#import matplotlib.pyplot as plt
from matplotlib import pyplot as plt
In [6]:
%matplotlib inline
In [7]:
HTTP_response = urllib.request.urlopen('http://www.hpca.ual.es/~vruiz/images/lena.png') # get the image
In [8]:
arr = np.asarray(bytearray(HTTP_response.read()), dtype=np.uint8) # convert the image to a numpy.ndarray
In [9]:
img = cv2.imdecode(arr,-1) # Decompress the image
In [10]:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # Convert to BGR -> RGB
In [11]:
plt.imshow(img)
Out[11]:
In [15]:
jp2 = glymur.Jp2k('lena.jp2', data=img, numres=5, cratios=[16,8,4,2,1])
In [22]:
#data = jp2.read(rlevel=2)
In [27]:
data = jp2.read(layer=10)
In [28]:
plt.imshow(data)
Out[28]:
In [15]:
for i in range(5):
print(i)
In [44]:
for i in range(5):
#jp2 = glymur.jp2box.ImageHeaderBox(laplacian[i+1].shape[0], laplacian[i+1].shape[1], num_components=3, signed=True, bits_per_component=8, compression=7, colorspace_unknown=False, ip_provided=False, length=0, offset=-1)
jp2 = glymur.Jp2k('laplacian_{}.jp2'.format(i+1), data=laplacian[i+1], numres=1)
#jp2 = glymur.Jp2k('laplacian_{}.jp2'.format(i+1), mode='wb')
#jp2.write(laplacian[i+1])
#print (jp2)
In [ ]:
In [ ]:
In [ ]: