Skip to content

img.WaveletImage

Bases: impl.WaveletImage

A class to load/save images of different formats and store them in WaveletBuffer

Source code in python/src/wavelet_buffer/img/wavelet_image.py
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
class WaveletImage(impl.WaveletImage):
    """A class to load/save images of different formats and store them in WaveletBuffer"""

    def __init__(
        self,
        signal_shape: List[int],
        signal_number: int,
        decomposition_steps: int,
        wavelet_type: WaveletType,
    ):
        """
        Args:
            signal_shape: for 1D signal with size N [N], for 2DN signal with size MXN, [M,N]
            signal_number: N for 2DN signal, e.g. RGB image would be 3 signals
            decomposition_steps: number of decomposition steps
            wavelet_type: type WaveletType.NONE, DB{1..5}, if it is NONE no wavelet composition
        """
        super().__init__(signal_shape, signal_number, decomposition_steps, wavelet_type)

    def import_from_file(
        self,
        file_path: str,
        denoiser: BaseDenoiser,
        codec: BaseCodec,
        start_channel: int = 0,
    ) -> None:
        """Import an image from file and decompose it with WaveletBuffer
        Args:
            file_path: path to image
            denoiser: denoising algorithm
            codec: a coodec for decoding the image format
            start_channel: need if you want to decode specific channel as a monochrome image
        """
        super(WaveletImage, self).import_from_file(
            file_path, denoiser, codec._impl, start_channel
        )

    def export_to_file(
        self, file_path: str, codec: BaseCodec, start_channel: int = 0
    ) -> None:
        """Encoding a wavelet image to a file with common image format e.g. JPEG
        Args:
            file_path: path to image
            codec:  a coodec for encoding the image format
            start_channel: need if you want to encode specific channel as a monochrome image, or you have
             a few images in the buffer
        """
        super(WaveletImage, self).export_to_file(file_path, codec._impl, start_channel)

    def import_from_string(
        self,
        data: bytes,
        denoiser: BaseDenoiser,
        codec: BaseCodec,
        start_channel: int = 0,
    ) -> None:
        """Import an image from byte sting and decompose it with WaveletBuffer
        Args:
            data: encoded image e.g. JPEG string
            denoiser: denoising algorithm
            codec: a coodec for decoding the image format
            start_channel: need if you want to decode specific channel as a monochrome image
        """
        super(WaveletImage, self).import_from_string(
            data, denoiser, codec._impl, start_channel
        )

    def export_to_string(self, codec: BaseCodec, start_channel: int = 0) -> bytes:
        """Encoding a wavelet image to a byte sting with common image format e.g. JPEG
        Args:
            codec:  a coodec for encoding the image format
            start_channel: need if you want to encode specific channel as a monochrome image, or you have
             a few images in the buffer
        Returns:
            encoded image e.g. JPEG string
        """
        return super(WaveletImage, self).export_to_string(codec._impl, start_channel)

    @staticmethod
    def load(file_path: str) -> "WaveletImage":
        """Deserialize a wavelet image from file
        Args:
            file_path:
        Returns:
            decompressed image
        """
        return impl.WaveletImage.load(file_path)

    def save(self, file_path: str) -> None:
        """Serialize image to a file
        Args:
            file_path:
        """
        super(WaveletImage, self).save(file_path)

    def distance(self, other: "WaveletImage") -> float:
        """Distance to other image. 1 - the same, 0 - something completely different"""
        return super(WaveletImage, self).distance(other)

    @property
    def buffer(self) -> WaveletBuffer:
        """Get wavelet buffer"""
        return super(WaveletImage, self).buffer

buffer: WaveletBuffer property

Get wavelet buffer

__init__(signal_shape, signal_number, decomposition_steps, wavelet_type)

Parameters:

Name Type Description Default
signal_shape List[int]

for 1D signal with size N [N], for 2DN signal with size MXN, [M,N]

required
signal_number int

N for 2DN signal, e.g. RGB image would be 3 signals

required
decomposition_steps int

number of decomposition steps

required
wavelet_type WaveletType

type WaveletType.NONE, DB{1..5}, if it is NONE no wavelet composition

required
Source code in python/src/wavelet_buffer/img/wavelet_image.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def __init__(
    self,
    signal_shape: List[int],
    signal_number: int,
    decomposition_steps: int,
    wavelet_type: WaveletType,
):
    """
    Args:
        signal_shape: for 1D signal with size N [N], for 2DN signal with size MXN, [M,N]
        signal_number: N for 2DN signal, e.g. RGB image would be 3 signals
        decomposition_steps: number of decomposition steps
        wavelet_type: type WaveletType.NONE, DB{1..5}, if it is NONE no wavelet composition
    """
    super().__init__(signal_shape, signal_number, decomposition_steps, wavelet_type)

distance(other)

Distance to other image. 1 - the same, 0 - something completely different

Source code in python/src/wavelet_buffer/img/wavelet_image.py
105
106
107
def distance(self, other: "WaveletImage") -> float:
    """Distance to other image. 1 - the same, 0 - something completely different"""
    return super(WaveletImage, self).distance(other)

export_to_file(file_path, codec, start_channel=0)

Encoding a wavelet image to a file with common image format e.g. JPEG

Parameters:

Name Type Description Default
file_path str

path to image

required
codec BaseCodec

a coodec for encoding the image format

required
start_channel int

need if you want to encode specific channel as a monochrome image, or you have a few images in the buffer

0
Source code in python/src/wavelet_buffer/img/wavelet_image.py
47
48
49
50
51
52
53
54
55
56
57
def export_to_file(
    self, file_path: str, codec: BaseCodec, start_channel: int = 0
) -> None:
    """Encoding a wavelet image to a file with common image format e.g. JPEG
    Args:
        file_path: path to image
        codec:  a coodec for encoding the image format
        start_channel: need if you want to encode specific channel as a monochrome image, or you have
         a few images in the buffer
    """
    super(WaveletImage, self).export_to_file(file_path, codec._impl, start_channel)

export_to_string(codec, start_channel=0)

Encoding a wavelet image to a byte sting with common image format e.g. JPEG

Parameters:

Name Type Description Default
codec BaseCodec

a coodec for encoding the image format

required
start_channel int

need if you want to encode specific channel as a monochrome image, or you have a few images in the buffer

0

Returns:

Type Description
bytes

encoded image e.g. JPEG string

Source code in python/src/wavelet_buffer/img/wavelet_image.py
77
78
79
80
81
82
83
84
85
86
def export_to_string(self, codec: BaseCodec, start_channel: int = 0) -> bytes:
    """Encoding a wavelet image to a byte sting with common image format e.g. JPEG
    Args:
        codec:  a coodec for encoding the image format
        start_channel: need if you want to encode specific channel as a monochrome image, or you have
         a few images in the buffer
    Returns:
        encoded image e.g. JPEG string
    """
    return super(WaveletImage, self).export_to_string(codec._impl, start_channel)

import_from_file(file_path, denoiser, codec, start_channel=0)

Import an image from file and decompose it with WaveletBuffer

Parameters:

Name Type Description Default
file_path str

path to image

required
denoiser BaseDenoiser

denoising algorithm

required
codec BaseCodec

a coodec for decoding the image format

required
start_channel int

need if you want to decode specific channel as a monochrome image

0
Source code in python/src/wavelet_buffer/img/wavelet_image.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def import_from_file(
    self,
    file_path: str,
    denoiser: BaseDenoiser,
    codec: BaseCodec,
    start_channel: int = 0,
) -> None:
    """Import an image from file and decompose it with WaveletBuffer
    Args:
        file_path: path to image
        denoiser: denoising algorithm
        codec: a coodec for decoding the image format
        start_channel: need if you want to decode specific channel as a monochrome image
    """
    super(WaveletImage, self).import_from_file(
        file_path, denoiser, codec._impl, start_channel
    )

import_from_string(data, denoiser, codec, start_channel=0)

Import an image from byte sting and decompose it with WaveletBuffer

Parameters:

Name Type Description Default
data bytes

encoded image e.g. JPEG string

required
denoiser BaseDenoiser

denoising algorithm

required
codec BaseCodec

a coodec for decoding the image format

required
start_channel int

need if you want to decode specific channel as a monochrome image

0
Source code in python/src/wavelet_buffer/img/wavelet_image.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def import_from_string(
    self,
    data: bytes,
    denoiser: BaseDenoiser,
    codec: BaseCodec,
    start_channel: int = 0,
) -> None:
    """Import an image from byte sting and decompose it with WaveletBuffer
    Args:
        data: encoded image e.g. JPEG string
        denoiser: denoising algorithm
        codec: a coodec for decoding the image format
        start_channel: need if you want to decode specific channel as a monochrome image
    """
    super(WaveletImage, self).import_from_string(
        data, denoiser, codec._impl, start_channel
    )

load(file_path) staticmethod

Deserialize a wavelet image from file

Parameters:

Name Type Description Default
file_path str
required

Returns:

Type Description
WaveletImage

decompressed image

Source code in python/src/wavelet_buffer/img/wavelet_image.py
88
89
90
91
92
93
94
95
96
@staticmethod
def load(file_path: str) -> "WaveletImage":
    """Deserialize a wavelet image from file
    Args:
        file_path:
    Returns:
        decompressed image
    """
    return impl.WaveletImage.load(file_path)

save(file_path)

Serialize image to a file

Parameters:

Name Type Description Default
file_path str
required
Source code in python/src/wavelet_buffer/img/wavelet_image.py
 98
 99
100
101
102
103
def save(self, file_path: str) -> None:
    """Serialize image to a file
    Args:
        file_path:
    """
    super(WaveletImage, self).save(file_path)