File size: 889 Bytes
8fd2f2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
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
30
from lib.farancia import IImage


def convert_range(video, output_range, input_range=None):
    if input_range is None:
        if video.min() < 0:
            input_range = [-1, 1]
        elif video.max() > 1:
            input_range = [0, 255]
        else:
            input_range = [0, 1]
    video = (video-input_range[0])/(input_range[1]-input_range[0])  # [0,1]
    video = video * (output_range[1]-output_range[0]) + output_range[0]
    return video


def concat_chunks(result_chunks):
    if not isinstance(result_chunks, list):
        result_chunks = [result_chunks]
    concatenated_result = None

    for chunk in result_chunks:
        assert chunk.min() >= 0
        chunk = IImage(chunk, vmin=0, vmax=255)
        if concatenated_result is None:
            concatenated_result = chunk
        else:
            concatenated_result &= chunk
    return concatenated_result