@@ -41,7 +41,13 @@ python -m pip install pylibjpeg-openjpeg
41
41
| [ 15444-1] ( https://www.iso.org/standard/78321.html ) | [ T.800] ( https://www.itu.int/rec/T-REC-T.800/en ) | [ JPEG 2000] ( https://jpeg.org/jpeg2000/ ) |
42
42
43
43
#### Encoding
44
- Encoding of JPEG 2000 images is not currently supported
44
+
45
+ Encoding of NumPy ndarrays is supported for the following:
46
+
47
+ * Array dtype: bool, uint8, int8, uint16, int16, uint32 and int32 (1-24 bit-depth only)
48
+ * Array shape: (rows, columns) and (rows, columns, planes)
49
+ * Number of rows/columns: up to 65535
50
+ * Number of planes: 1, 3 or 4
45
51
46
52
47
53
### Transfer Syntaxes
@@ -81,3 +87,46 @@ with open('filename.j2k', 'rb') as f:
81
87
# Or simply...
82
88
arr = decode(' filename.j2k' )
83
89
```
90
+
91
+ #### Standalone JPEG encoding
92
+
93
+ Lossless encoding of RGB with multiple-component transformation:
94
+
95
+ ``` python
96
+
97
+ import numpy as np
98
+ from openjpeg import encode
99
+
100
+ arr = np.random.randint(low = 0 , high = 65535 , size = (100 , 100 , 3 ), dtype = " uint8" )
101
+ encode(arr, photometric_interpretation = 1 ) # 1: sRGB
102
+ ```
103
+
104
+ Lossy encoding of a monochrome image using compression ratios:
105
+
106
+ ``` python
107
+
108
+ import numpy as np
109
+ from openjpeg import encode
110
+
111
+ arr = np.random.randint(low = - 2 ** 15 , high = 2 ** 15 - 1 , size = (100 , 100 ), dtype = " int8" )
112
+ # You must determine your own values for `compression_ratios`
113
+ # as these are for illustration purposes only
114
+ encode(arr, compression_ratios = [2 , 4 , 6 ])
115
+ ```
116
+
117
+ Lossy encoding of a monochrome image using peak signal-to-noise ratios:
118
+
119
+ ``` python
120
+
121
+ import numpy as np
122
+ from openjpeg import encode
123
+
124
+ arr = np.random.randint(low = - 2 ** 15 , high = 2 ** 15 - 1 , size = (100 , 100 ), dtype = " int8" )
125
+ # You must determine your own values for `signal_noise_ratios`
126
+ # as these are for illustration purposes only
127
+ encode(arr, signal_noise_ratios = [50 , 80 , 100 ])
128
+ ```
129
+
130
+ See the docstring for the [ encode() function] [ 2 ] for full details.
131
+
132
+ [ 2 ] : https://github.com/pydicom/pylibjpeg-openjpeg/blob/main/openjpeg/utils.py#L428
0 commit comments