Skip to content

Commit 4e7b81f

Browse files
committed
Fixes #3: Saving non int data to JPEG2000
1 parent e882850 commit 4e7b81f

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
See DataLab [roadmap page](https://cdlapp.readthedocs.io/en/latest/dev/roadmap.html)
44
for future and past milestones.
55

6+
## DataLab Version 0.9.1 ##
7+
8+
🛠️ Bug fixes:
9+
10+
* [Issue #3](https://github.com/Codra-Ingenierie-Informatique/DataLab/issues/3) - Save image to JPEG2000: 'OSError: encoder error -2 when writing image file'
11+
612
## DataLab Version 0.9.0 ##
713

814
New dependencies:

cdl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import os
1818

19-
__version__ = "0.9.0"
19+
__version__ = "0.9.1"
2020
__docurl__ = "https://cdlapp.readthedocs.io/en/latest/"
2121
__homeurl__ = "https://codra-ingenierie-informatique.github.io/DataLab/"
2222
__supporturl__ = (

cdl/core/io/image/formats.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class ClassicsImageFormat(ImageFormatBase):
2525
"""Object representing classic image file types"""
2626

2727
FORMAT_INFO = FormatInfo(
28-
name="BMP, JPEG, PNG, TIFF",
29-
extensions="*.bmp *.jpg *.jpeg *.png *.tif *.tiff",
28+
name="BMP, JPEG, PNG, TIFF JPEG2000",
29+
extensions="*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.jp2",
3030
readable=True,
3131
writeable=True,
3232
)
@@ -39,22 +39,16 @@ def read_data(filename: str) -> np.ndarray:
3939
def write(self, filename: str, obj: ImageObj) -> None:
4040
"""Write data to file"""
4141
data = obj.data
42-
if osp.splitext(filename)[1].lower() in (".bmp", ".jpg", ".jpeg", ".png"):
43-
data = obj.data.astype(np.uint8)
42+
ext = osp.splitext(filename)[1].lower()
43+
if ext in (".bmp", ".jpg", ".jpeg", ".png"):
44+
if data.dtype is not np.uint8:
45+
data = obj.data.astype(np.uint8)
46+
if ext in (".jp2",):
47+
if data.dtype not in (np.uint8, np.uint16):
48+
data = obj.data.astype(np.uint16)
4449
skimage.io.imsave(filename, data, check_contrast=False)
4550

4651

47-
class JPEG2000ImageFormat(ClassicsImageFormat):
48-
"""Object representing JPEG2000 image file type"""
49-
50-
FORMAT_INFO = FormatInfo(
51-
name="JPEG2000",
52-
extensions="*.jp2",
53-
readable=True,
54-
writeable=True,
55-
)
56-
57-
5852
class NumPyImageFormat(ImageFormatBase):
5953
"""Object representing NumPy image file type"""
6054

0 commit comments

Comments
 (0)