コード例 #1
0
def process(file):
    path = pathlib.Path(file)
    filename = path.stem
    extension = path.suffix

    print("processing {:}".format(filename))
    try:
        image = colour.cctf_decoding(colour.io.read_image(os.path.join(
            IN_DIR, file),
                                                          method='Imageio'),
                                     function='sRGB')

        corrected_image = numpy.clip(
            ColorCorrect.color_correct(image,
                                       SpyderCHECKR24.colour_checker,
                                       method='Finlayson 2015'), 0.0, 1.0)

        output_filename = os.path.join(OUT_DIR,
                                       filename + '_corrected' + extension)
        colour.io.write_image(colour.cctf_encoding(corrected_image,
                                                   function='sRGB'),
                              output_filename,
                              bit_depth='uint8',
                              method='Imageio')
    except:
        print("error processing {:}".format(filename))
コード例 #2
0
def demosaicking(image: np.ndarray,
                 method: str = "bilinear",
                 pattern: str = "RGGB") -> np.ndarray:
    """Returns the demosaicked image given a method.

    Parameters
    -------------------
    image: np.ndarray,
        The image to be demosaicked.
    method: str,
        Demosaicking method to be applied.
    pattern: str,
        Arrangement of the colour filters on the pixel array.
        Possible patterns are: {RGGB, BGGR, GRBG, GBRG}.

    Raises
    ------------------
    ValueError,
        If given method does not exist.

    Returns
    -------------------
    Returns the demosaicked image.
    """
    image_rgb = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
    image_cfa = mosaicing_CFA_Bayer(image_rgb, pattern=pattern) / 255

    if method == 'bilinear':
        image_demo = ((cctf_encoding(
            demosaicing_CFA_Bayer_bilinear(image_cfa, pattern=pattern))) *
                      255).astype(np.uint8)
    elif method == 'malvar':
        image_demo = ((cctf_encoding(
            demosaicing_CFA_Bayer_Malvar2004(image_cfa, pattern=pattern))) *
                      255).astype(np.uint8)
    elif method == 'menon':
        image_demo = ((cctf_encoding(
            demosaicing_CFA_Bayer_Menon2007(image_cfa, pattern=pattern))) *
                      255).astype(np.uint8)
    else:
        raise ValueError(
            'Given method \'{}\' does not belong to possible methods. '
            'Valid methods are: \'bilinear\', \'malvar\' and \'menon\'.'.
            format(method))

    return cv2.cvtColor(image_demo, cv2.COLOR_RGB2GRAY)
コード例 #3
0
    def readCurrentImage(self):
        img = self.__images[self.__current_image]

        if img['pds_data'] is None:
            # 读入pds label
            img['pds_data'] = pds4_tools.read('%s/%s' %(img['path'], img['filename']))

            # 将图像数据提取出来
            img['raw_data'] = np.asanyarray(img['pds_data'][0].data)
            print(img['raw_data'].shape, img['raw_data'].ndim)
            img['raw_data'] = img['raw_data'] / 1023      #10位的图像数据归一化 

            # de-bayer
            rgb_data = colour.cctf_encoding(colour_demosaicing.demosaicing_CFA_Bayer_bilinear(img['raw_data'], 'RGGB')) 
            print(rgb_data.shape, rgb_data.ndim)
            img['rgb_data'] = rgb_data

            ## 直方图拉伸
            #lower, upper = np.percentile(rgb_data, (0.2,99.8))
            #print(lower, upper)
            #scale_data = exposure.rescale_intensity(rgb_data, in_range=(lower, upper)) 

        return img
コード例 #4
0
                                   "resources")

colour_style()

ISHIHARA_CBT_3_IMAGE = colour.cctf_decoding(
    colour.read_image(
        os.path.join(RESOURCES_DIRECTORY,
                     "Ishihara_Colour_Blindness_Test_Plate_3.png")),
    function="sRGB",
)

message_box("Colour Blindness Plots")

message_box('Displaying "Ishihara Colour Blindness Test - Plate 3".')
plot_image(
    colour.cctf_encoding(ISHIHARA_CBT_3_IMAGE),
    text_kwargs={
        "text": "Normal Trichromat",
        "color": "black"
    },
)

print("\n")

message_box(
    'Simulating average "Protanomaly" on '
    '"Ishihara Colour Blindness Test - Plate 3" with Machado (2010) model and '
    "pre-computed matrix.")
plot_cvd_simulation_Machado2009(
    ISHIHARA_CBT_3_IMAGE,
    "Protanomaly",
コード例 #5
0
from colour.utilities.verbose import message_box

RESOURCES_DIRECTORY = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                   'resources')

colour_style()

ISHIHARA_CBT_3_IMAGE = colour.cctf_decoding(colour.read_image(
    os.path.join(RESOURCES_DIRECTORY,
                 'Ishihara_Colour_Blindness_Test_Plate_3.png')),
                                            function='sRGB')

message_box('Colour Blindness Plots')

message_box('Displaying "Ishihara Colour Blindness Test - Plate 3".')
plot_image(colour.cctf_encoding(ISHIHARA_CBT_3_IMAGE),
           text_parameters={
               'text': 'Normal Trichromat',
               'color': 'black'
           })

print('\n')

message_box('Simulating average "Protanomaly" on '
            '"Ishihara Colour Blindness Test - Plate 3" with Machado (2010) '
            'model and pre-computed matrix.')
plot_cvd_simulation_Machado2009(ISHIHARA_CBT_3_IMAGE,
                                'Protanomaly',
                                0.5,
                                text_parameters={
                                    'text': 'Protanomaly - 50%',
コード例 #6
0
def apply_cctf_encoding(RGB_input,
                        transfer_function_name="Gamma 2.2",
                        exponent=None):
    return colour.cctf_encoding(RGB_input,
                                function=transfer_function_name,
                                negative_number_handling="Clamp")
コード例 #7
0
 def apply_odt_cctf(self, in_rgb):
     cctf_func = ODT_DICO.get(self.odt)[0]
     result_cctf = colour.cctf_encoding(in_rgb, cctf_func)
     return result_cctf
コード例 #8
0
    -----------------------
    <BLANKLINE>
    Dimensions : 3
    Domain     : [[ 0.  0.  0.]
                    [ 1.  1.  1.]]
    Size       : (33, 33, 33, 3)
    """
    size = self.size
    LUT_inverse = colour.LUT3D(size=size, name='Inverted Format')
    indexes = LUT_inverse.table

    tree = cKDTree(self.table.reshape(-1, 3))
    query = tree.query(indexes)[-1]

    LUT_inverse.table = indexes.reshape(-1, 3)[query].reshape(
        [size, size, size, 3])

    return LUT_inverse


RGB = [0.18, 0.18, 0.18]
LUT = colour.LUT3D()
LUT.table = colour.cctf_encoding(LUT.table)
RGB_a = LUT.apply(RGB)
LUT_inverse = invert(LUT)
RGB_i = LUT_inverse.apply(RGB_a)

print(RGB)
print(RGB_a)
print(RGB_i)