Skip to content

img.codecs

Interface for codes to decode/encode images from/to different image formats

Source code in python/src/wavelet_buffer/img/codecs.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class BaseCodec:
    """Interface for codes to decode/encode images from/to different image formats"""

    def decode(self, blob: bytes) -> "np.ndarray[np.float32]":
        """Decode an image from bytes to a numpy image
        Args:
            blob: serialized image e.g. JPEG
        Returns:
            image as numpy array
        """
        raise NotImplemented()

    def encode(self, data: "np.ndarray[np.float32]", start_channel: int = 0) -> bytes:
        """Encode a numpy image to byte string
        Args:
            data: numpy image
            start_channel: start channel for conversion
        Returns:
            serialized image e.g. JPEG
        """
        raise NotImplemented()

    def channel_number(self) -> int:
        """Return number ofr channel RGB=3, Gray=1"""
        raise NotImplemented()

channel_number()

Return number ofr channel RGB=3, Gray=1

Source code in python/src/wavelet_buffer/img/codecs.py
27
28
29
def channel_number(self) -> int:
    """Return number ofr channel RGB=3, Gray=1"""
    raise NotImplemented()

decode(blob)

Decode an image from bytes to a numpy image

Parameters:

Name Type Description Default
blob bytes

serialized image e.g. JPEG

required

Returns:

Type Description
np.ndarray[np.float32]

image as numpy array

Source code in python/src/wavelet_buffer/img/codecs.py
 8
 9
10
11
12
13
14
15
def decode(self, blob: bytes) -> "np.ndarray[np.float32]":
    """Decode an image from bytes to a numpy image
    Args:
        blob: serialized image e.g. JPEG
    Returns:
        image as numpy array
    """
    raise NotImplemented()

encode(data, start_channel=0)

Encode a numpy image to byte string

Parameters:

Name Type Description Default
data np.ndarray[np.float32]

numpy image

required
start_channel int

start channel for conversion

0

Returns:

Type Description
bytes

serialized image e.g. JPEG

Source code in python/src/wavelet_buffer/img/codecs.py
17
18
19
20
21
22
23
24
25
def encode(self, data: "np.ndarray[np.float32]", start_channel: int = 0) -> bytes:
    """Encode a numpy image to byte string
    Args:
        data: numpy image
        start_channel: start channel for conversion
    Returns:
        serialized image e.g. JPEG
    """
    raise NotImplemented()

Bases: BaseCodec

Codec for JPEG <-> numpy RGB image conversion

Source code in python/src/wavelet_buffer/img/codecs.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class RgbJpeg(BaseCodec):
    """Codec for JPEG <-> numpy RGB image conversion"""

    def __init__(self, write_quality: float = 1.0):
        """
        Args:
            write_quality: quality of encoded image. Should be from 0 to 1.0
        """
        self._impl = impl.RgbJpeg(write_quality)

    def decode(self, blob: bytes) -> "np.ndarray[np.float32]":
        return self._impl.decode(blob)

    def encode(self, data: "np.ndarray[np.float32]", start_channel: int = 0) -> bytes:
        return self._impl.encode(data, start_channel)

    def channel_number(self) -> int:
        return self._impl.channel_number()

__init__(write_quality=1.0)

Parameters:

Name Type Description Default
write_quality float

quality of encoded image. Should be from 0 to 1.0

1.0
Source code in python/src/wavelet_buffer/img/codecs.py
35
36
37
38
39
40
def __init__(self, write_quality: float = 1.0):
    """
    Args:
        write_quality: quality of encoded image. Should be from 0 to 1.0
    """
    self._impl = impl.RgbJpeg(write_quality)

Bases: BaseCodec

Codec for JPEG <-> numpy HSL image conversion

Source code in python/src/wavelet_buffer/img/codecs.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class HslJpeg(BaseCodec):
    """Codec for JPEG <-> numpy HSL image conversion"""

    def __init__(self, write_quality: float = 1.0):
        """
        Args:
            write_quality: quality of encoded image. Should be from 0 to 1.0
        """
        self._impl = impl.HslJpeg(write_quality)

    def decode(self, blob: bytes) -> "np.ndarray[np.float32]":
        return self._impl.decode(blob)

    def encode(self, data: "np.ndarray[np.float32]", start_channel: int = 0) -> bytes:
        return self._impl.encode(data, start_channel)

    def channel_number(self) -> int:
        return self._impl.channel_number()

__init__(write_quality=1.0)

Parameters:

Name Type Description Default
write_quality float

quality of encoded image. Should be from 0 to 1.0

1.0
Source code in python/src/wavelet_buffer/img/codecs.py
55
56
57
58
59
60
def __init__(self, write_quality: float = 1.0):
    """
    Args:
        write_quality: quality of encoded image. Should be from 0 to 1.0
    """
    self._impl = impl.HslJpeg(write_quality)

Bases: BaseCodec

Codec for JPEG <-> numpy monochrome image conversion

Source code in python/src/wavelet_buffer/img/codecs.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class GrayJpeg(BaseCodec):
    """Codec for JPEG  <-> numpy monochrome image conversion"""

    def __init__(self, write_quality: float = 1.0):
        """
        Args:
            write_quality: quality of encoded image. Should be from 0 to 1.0
        """
        self._impl = impl.GrayJpeg(write_quality)

    def decode(self, blob: bytes) -> "np.ndarray[np.float32]":
        return self._impl.decode(blob)

    def encode(self, data: "np.ndarray[np.float32]", start_channel: int = 0) -> bytes:
        return self._impl.encode(data, start_channel)

    def channel_number(self) -> int:
        return self._impl.channel_number()

__init__(write_quality=1.0)

Parameters:

Name Type Description Default
write_quality float

quality of encoded image. Should be from 0 to 1.0

1.0
Source code in python/src/wavelet_buffer/img/codecs.py
75
76
77
78
79
80
def __init__(self, write_quality: float = 1.0):
    """
    Args:
        write_quality: quality of encoded image. Should be from 0 to 1.0
    """
    self._impl = impl.GrayJpeg(write_quality)