deprecated read method, removed write method, closes #299
use array-style slicing instead. Many former read methods are now properties. Many former write method parameters are now moved into the constructor.
This commit is contained in:
parent
7cdc5c6828
commit
03cb19d22b
16 changed files with 1132 additions and 1188 deletions
|
|
@ -14,27 +14,22 @@ retrieve a full resolution and first lower-resolution image ::
|
|||
>>> jp2file = glymur.data.nemo() # just a path to a JPEG2000 file
|
||||
>>> jp2 = glymur.Jp2k(jp2file)
|
||||
>>> fullres = jp2[:]
|
||||
>>> print(fullres.shape)
|
||||
>>> fullres.shape
|
||||
(1456, 2592, 3)
|
||||
>>> thumbnail = jp2[::2, ::2]
|
||||
>>> print(thumbnail.shape)
|
||||
>>> thumbnail.shape
|
||||
(728, 1296, 3)
|
||||
|
||||
The :py:meth:`read` method exposes many more options for other JPEG 2000
|
||||
features such as quality layers.
|
||||
|
||||
... write images?
|
||||
=================
|
||||
So long as the image data can fit entirely into memory, array-style slicing may
|
||||
also be used to write JPEG 2000 files.
|
||||
It's pretty simple, just supply the image data as the 2nd argument to the Jp2k
|
||||
constructor.
|
||||
|
||||
>>> import glymur, numpy as np
|
||||
>>> jp2 = glymur.Jp2k('zeros.jp2', mode='wb')
|
||||
>>> jp2[:] = np.zeros((640, 480), dtype=np.uint8)
|
||||
>>> data = np.zeros((640, 480), dtype=np.uint8)
|
||||
>>> jp2 = glymur.Jp2k('zeros.jp2', data=data)
|
||||
|
||||
The :py:meth:`write` method exposes many more options for other JPEG 2000
|
||||
features. You should have OpenJPEG version 1.5 or more recent before writing
|
||||
JPEG 2000 images.
|
||||
You should have OpenJPEG version 1.5 or more recent before writing JPEG 2000 images.
|
||||
|
||||
... display metadata?
|
||||
=====================
|
||||
|
|
@ -354,15 +349,14 @@ image isn't square. ::
|
|||
>>> import numpy as np
|
||||
>>> import glymur
|
||||
>>> from glymur import Jp2k
|
||||
>>> rgb = Jp2k(glymur.data.goodstuff()).read()
|
||||
>>> rgb = Jp2k(glymur.data.goodstuff())[:]
|
||||
>>> lx, ly = rgb.shape[0:2]
|
||||
>>> X, Y = np.ogrid[0:lx, 0:ly]
|
||||
>>> mask = ly**2*(X - lx / 2) ** 2 + lx**2*(Y - ly / 2) ** 2 > (lx * ly / 2)**2
|
||||
>>> alpha = 255 * np.ones((lx, ly, 1), dtype=np.uint8)
|
||||
>>> alpha[mask] = 0
|
||||
>>> rgba = np.concatenate((rgb, alpha), axis=2)
|
||||
>>> jp2 = Jp2k('tmp.jp2', 'wb')
|
||||
>>> jp2[:] = rgba
|
||||
>>> jp2 = Jp2k('tmp.jp2', data=rgba)
|
||||
|
||||
Next we need to specify what types of channels we have.
|
||||
The first three channels are color channels, but we identify the fourth as
|
||||
|
|
@ -465,8 +459,7 @@ http://photojournal.jpl.nasa.gov/tiff/PIA17145.tif info JPEG 2000::
|
|||
>>> import skimage.io
|
||||
>>> image = skimage.io.imread('PIA17145.tif')
|
||||
>>> from glymur import Jp2k
|
||||
>>> jp2 = Jp2k('PIA17145.jp2', 'wb')
|
||||
>>> jp2[:] = image
|
||||
>>> jp2 = Jp2k('PIA17145.jp2', data=image)
|
||||
|
||||
Next you can extract the XMP metadata.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue