From d18d6aa0b0bbdfbfca0d1d669054dd18d145f6a9 Mon Sep 17 00:00:00 2001 From: jevans Date: Mon, 10 Jun 2013 18:43:52 -0400 Subject: [PATCH 1/5] Reordering documents, make api go last. Fixes #25 Should revisit this, is it a bug in sphinx? --- docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 1a7ddda..bcc2d75 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -13,9 +13,9 @@ Contents: :maxdepth: 2 introduction - api how_do_i roadmap + api ------------------ Indices and tables From 61712442ebe79181e9ec8b1aff992243eaad4c0c Mon Sep 17 00:00:00 2001 From: jevans Date: Tue, 11 Jun 2013 19:07:44 -0400 Subject: [PATCH 2/5] Added reduce=-1 to get lowest resolution thumbnail. Closes #38. --- docs/source/how_do_i.rst | 12 ++++++++++++ glymur/jp2k.py | 19 +++++++++++++++++-- glymur/test/test_jp2k.py | 13 +++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/docs/source/how_do_i.rst b/docs/source/how_do_i.rst index 82f03bd..5206f79 100644 --- a/docs/source/how_do_i.rst +++ b/docs/source/how_do_i.rst @@ -3,6 +3,18 @@ How do I...? ------------ +Read the lowest resolution thumbnail? +===================================== +Printing the Jp2k object should reveal the number of resolutions (look in the +COD segment section), but you can take a shortcut by supplying -1 as the reduce +level. + + >>> import pkg_resources + >>> import glymur + >>> file = pkg_resources.resource_filename(glymur.__name__, "data/nemo.jp2") + >>> j = glymur.Jp2k(file) + >>> thumbnail = j.read(reduce=-1) + Display metadata? ================= There are two ways. From the unix command line, the script *jp2dump* is diff --git a/glymur/jp2k.py b/glymur/jp2k.py index a42e291..adba2cc 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -407,7 +407,8 @@ class Jp2k(Jp2kBox): layer : int, optional Number of quality layer to decode. reduce : int, optional - Factor by which to reduce output resolution. + Factor by which to reduce output resolution. Use -1 to get the + lowest resolution thumbnail. area : tuple, optional Specifies decoding image area, (first_row, first_col, last_row, last_col) @@ -432,7 +433,15 @@ class Jp2k(Jp2kBox): >>> import pkg_resources as pkg >>> jfile = pkg.resource_filename(glymur.__name__, "data/nemo.jp2") >>> jp = glymur.Jp2k(jfile) - >>> data = jp.read(reduce=1) + >>> image = jp.read() + >>> image.shape + (1456, 2592, 3) + + Read the lowest resolution thumbnail. + + >>> thumbnail = jp.read(reduce=-1) + >>> thumbnail.shape + (46, 81, 3) """ # Check for differing subsample factors. codestream = self.get_codestream(header_only=True) @@ -490,6 +499,12 @@ class Jp2k(Jp2kBox): dparam.decod_format = self._codec_format dparam.cp_layer = layer + + if reduce == -1: + # Get the lowest resolution thumbnail. + codestream = self.get_codestream() + reduce = codestream.segment[2].SPcod[4] + dparam.cp_reduce = reduce if area is not None: if area[0] < 0 or area[1] < 0: diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 5e9ab9b..249bc5e 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -53,7 +53,8 @@ class TestJp2k(unittest.TestCase): @classmethod def setUpClass(cls): - # Setup a JP2 file with a bad XML box. + # Setup a JP2 file with a bad XML box. We only need to do this once + # per class rather than once per test. jp2file = pkg_resources.resource_filename(glymur.__name__, "data/nemo.jp2") with tempfile.NamedTemporaryFile(suffix='.jp2', delete=False) as tfile: @@ -92,10 +93,18 @@ class TestJp2k(unittest.TestCase): "Uses features introduced in 3.2.") def test_invalid_xml_box_warning(self): # Should be able to recover from xml box with bad xml. - # Just verify that a warning is issued on 3.2+ + # Just verify that a warning is issued on 3.3+ with self.assertWarns(UserWarning) as cw: jp2k = Jp2k(self._bad_xml_file) + def test_reduce_max(self): + # Verify that reduce=-1 gets us the lowest resolution image + j = Jp2k(self.jp2file) + thumbnail1 = j.read(reduce=-1) + thumbnail2 = j.read(reduce=5) + np.testing.assert_array_equal(thumbnail1, thumbnail2) + self.assertEqual(thumbnail1.shape, (46, 81, 3)) + def test_invalid_xml_box(self): # Should be able to recover from xml box with bad xml. with warnings.catch_warnings(): From e542b43a51f5470aeaa965cdd6e6673f60a1c2be Mon Sep 17 00:00:00 2001 From: jevans Date: Tue, 11 Jun 2013 19:16:35 -0400 Subject: [PATCH 3/5] Recording enhancement for reduce=-1 --- CHANGES.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 2cb6883..f85afa4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,5 @@ +Jun 11, 2013 - Added reduce=-1 option to get lowest resolution thumbnail + Jun 07, 2013 - v0.1.7 Changed Exif dictionary names from ['Exif', 'Photo', 'Iop', 'GPSInfo'] to ['Image', 'Photo', 'Iop', 'GPSInfo']. From 93132bf86d653fa99aaaeae8760be43cb411aaed Mon Sep 17 00:00:00 2001 From: John Evans Date: Fri, 14 Jun 2013 14:12:48 -0400 Subject: [PATCH 4/5] Minor doc fixes. --- docs/source/how_do_i.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/how_do_i.rst b/docs/source/how_do_i.rst index 5206f79..d4a91bf 100644 --- a/docs/source/how_do_i.rst +++ b/docs/source/how_do_i.rst @@ -7,7 +7,7 @@ Read the lowest resolution thumbnail? ===================================== Printing the Jp2k object should reveal the number of resolutions (look in the COD segment section), but you can take a shortcut by supplying -1 as the reduce -level. +level. :: >>> import pkg_resources >>> import glymur @@ -38,7 +38,7 @@ codestream box, only the main header is printed. It is possible to print Work with XMP UUIDs? ==================== -The example JP2 file shipped with glymur has an XMP UUID:: +The example JP2 file shipped with glymur has an XMP UUID. :: >>> import pkg_resources >>> from glymur import Jp2k From 00db032bca35c4db6c0dfa1dc14377f05c779655 Mon Sep 17 00:00:00 2001 From: John Evans Date: Fri, 14 Jun 2013 14:13:02 -0400 Subject: [PATCH 5/5] Bumping for 1.1.8 release. --- CHANGES.txt | 3 ++- docs/source/conf.py | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f85afa4..3e761d3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ -Jun 11, 2013 - Added reduce=-1 option to get lowest resolution thumbnail +Jun 11, 2013 - v0.1.8 Added reduce=-1 option to get lowest resolution + thumbnail. Jun 07, 2013 - v0.1.7 Changed Exif dictionary names from ['Exif', 'Photo', 'Iop', 'GPSInfo'] to ['Image', 'Photo', 'Iop', 'GPSInfo']. diff --git a/docs/source/conf.py b/docs/source/conf.py index 262e5d8..10d03c2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -78,7 +78,7 @@ copyright = u'2013, John Evans' # The short X.Y version. version = '0.1' # The full version, including alpha/beta/rc tags. -release = '0.1.7' +release = '0.1.8' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/setup.py b/setup.py index 6e968ae..4f32597 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from distutils.core import setup kwargs = {'name': 'Glymur', - 'version': '0.1.7', + 'version': '0.1.8', 'description': 'Tools for accessing JPEG2000 files', 'long_description': open('README.md').read(), 'author': 'John Evans',