File: resize_jp2.py

package info (click to toggle)
sunpy 7.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,584 kB
  • sloc: python: 41,702; ansic: 1,710; makefile: 39
file content (19 lines) | stat: -rw-r--r-- 648 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import glymur
from scipy.ndimage import zoom


def resize_jp2(jp2file: str, scale: float) -> None:
    """
    Resize a JPEG2000 file by a given scale factor.

    It uses zoom from scipy.ndimage to resize the image data, so factor is the inverse.

    It will copy the XML metadata from the original file to the new one.
    It will not overwrite the original file.
    """
    original_jp2 = glymur.Jp2k(jp2file)
    rescaled_data = zoom(original_jp2[:], scale)
    new_file = glymur.Jp2k(f'{jp2file}_rescale.jp2', rescaled_data)
    for box in original_jp2.box:
        if isinstance(box, glymur.jp2box.XMLBox):
            new_file.append(box)