Skip to content

Commit

Permalink
Add encoding using a buffer and bug fixes (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaramallion authored Mar 23, 2024
1 parent 6a99340 commit f45f309
Show file tree
Hide file tree
Showing 11 changed files with 4,726 additions and 1,159 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Encoding of NumPy ndarrays is supported for the following:
* Number of rows/columns: up to 65535
* Number of planes: 1, 3 or 4


### Transfer Syntaxes
| UID | Description |
| --- | --- |
Expand Down Expand Up @@ -95,38 +94,38 @@ Lossless encoding of RGB with multiple-component transformation:
```python

import numpy as np
from openjpeg import encode
from openjpeg import encode_array

arr = np.random.randint(low=0, high=65535, size=(100, 100, 3), dtype="uint8")
encode(arr, photometric_interpretation=1) # 1: sRGB
arr = np.random.randint(low=0, high=65536, size=(100, 100, 3), dtype="uint8")
encode_array(arr, photometric_interpretation=1) # 1: sRGB
```

Lossy encoding of a monochrome image using compression ratios:

```python

import numpy as np
from openjpeg import encode
from openjpeg import encode_array

arr = np.random.randint(low=-2**15, high=2**15 - 1, size=(100, 100), dtype="int8")
arr = np.random.randint(low=-2**15, high=2**15, size=(100, 100), dtype="int8")
# You must determine your own values for `compression_ratios`
# as these are for illustration purposes only
encode(arr, compression_ratios=[2, 4, 6])
encode_array(arr, compression_ratios=[5, 2])
```

Lossy encoding of a monochrome image using peak signal-to-noise ratios:

```python

import numpy as np
from openjpeg import encode
from openjpeg import encode_array

arr = np.random.randint(low=-2**15, high=2**15 - 1, size=(100, 100), dtype="int8")
arr = np.random.randint(low=-2**15, high=2**15, size=(100, 100), dtype="int8")
# You must determine your own values for `signal_noise_ratios`
# as these are for illustration purposes only
encode(arr, signal_noise_ratios=[50, 80, 100])
encode_array(arr, signal_noise_ratios=[50, 80, 100])
```

See the docstring for the [encode() function][2] for full details.
See the docstring for the [encode_array() function][2] for full details.

[2]: https://github.com/pydicom/pylibjpeg-openjpeg/blob/main/openjpeg/utils.py#L428
[2]: https://github.com/pydicom/pylibjpeg-openjpeg/blob/main/openjpeg/utils.py#L429
1 change: 0 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import os
import sys
from pathlib import Path
import shutil
import subprocess
Expand Down
3 changes: 2 additions & 1 deletion lib/interface/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ extern int Decode(PyObject* fd, unsigned char *out, int codec_format)
}

// Convert colour space (if required)
// Colour space information is only available with JP2
if (
image->color_space != OPJ_CLRSPC_SYCC
&& image->numcomps == 3
Expand Down Expand Up @@ -668,7 +669,7 @@ extern int Decode(PyObject* fd, unsigned char *out, int codec_format)
}
}
} else {
// Support for more than 16-bits per component is not implemented
// Support for more than 32-bits per component is not implemented
return_code = 7;
goto failure;
}
Expand Down
Loading

0 comments on commit f45f309

Please sign in to comment.