def test_convert_dng_files_to_intermediate_files(self): """ Tests :func:`colour_hdri.process.conversion.\ convert_dng_files_to_intermediate_files` definition. """ reference_dng_files = sorted( filter_files(PROCESS_DIRECTORY, ('dng',))) tests_dng_files = [os.path.join(self.__temporary_directory, os.path.basename(reference_dng_file)) for reference_dng_file in reference_dng_files] for reference_dng_file, tests_dng_file in zip(reference_dng_files, tests_dng_files): shutil.copyfile(reference_dng_file, tests_dng_file) reference_tiff_files = sorted( filter_files(PROCESS_DIRECTORY, ('tiff',))) test_tiff_files = sorted(convert_dng_files_to_intermediate_files( tests_dng_files, self.__temporary_directory)) for test_tiff_file, reference_tiff_file in zip( test_tiff_files, reference_tiff_files): np.testing.assert_almost_equal( read_image(str(test_tiff_file)), read_image(str(reference_tiff_file)), decimal=7)
def test_highlights_recovery_blend(self): """ Tests :func:`colour_hdri.recovery.highlights.highlights_recovery_blend` definition. """ multipliers = np.array([2.42089718, 1.00000000, 1.54687415]) multipliers /= np.max(multipliers) reference_raw_file = RAW_IMAGES[1] test_raw_file = os.path.join(self._temporary_directory, os.path.basename(reference_raw_file)) shutil.copyfile(reference_raw_file, test_raw_file) command = [RAW_CONVERTER] + shlex.split( RAW_D_CONVERSION_ARGUMENTS.format(test_raw_file), posix=not _IS_WINDOWS_PLATFORM) subprocess.call(command) # nosec test_tiff_file = read_image( str(re.sub('\\.CR2$', '.tiff', test_raw_file)))[::10, ::10, :] test_tiff_file *= multipliers test_tiff_file = highlights_recovery_blend(test_tiff_file, multipliers) test_tiff_file = camera_space_to_sRGB(test_tiff_file, XYZ_TO_CAMERA_SPACE_MATRIX) reference_exr_path = os.path.join( RECOVERY_DIRECTORY, os.path.basename(re.sub('\\.CR2$', '_Blend.exr', test_raw_file))) reference_exr_file = read_image(str(reference_exr_path)) np.testing.assert_allclose(test_tiff_file, reference_exr_file, rtol=0.0001, atol=0.0001)
def test_demosaicing_CFA_Bayer_Menon2007(self): """ Tests :func:`colour_demosaicing.bayer.demosaicing.menon2007.\ demosaicing_CFA_Bayer_Menon2007` definition. """ for pattern in ('RGGB', 'BGGR', 'GRBG', 'GBRG'): CFA = os.path.join(BAYER_DIRECTORY, 'Lighthouse_CFA_{0}.exr') RGB = os.path.join(BAYER_DIRECTORY, 'Lighthouse_Menon2007_{0}.exr') np.testing.assert_almost_equal(demosaicing_CFA_Bayer_Menon2007( read_image(str(CFA.format(pattern)))[..., 0], pattern), read_image(str( RGB.format(pattern))), decimal=7) RGB = os.path.join(BAYER_DIRECTORY, 'Lighthouse_Menon2007_NR_{0}.exr') np.testing.assert_almost_equal( demosaicing_CFA_Bayer_Menon2007(read_image( str(CFA.format(pattern)))[..., 0], pattern, refining_step=False), read_image(str(RGB.format(pattern))), decimal=7)
def test_highlight_regions_variance_minimization(self): """ Tests :func:`colour_hdri.sampling.variance_minimization.\ highlight_regions_variance_minimization` definition. """ colourspace = RGB_COLOURSPACES['sRGB'] image = read_image( str( os.path.join( SAMPLING_DIRECTORY, 'tests_light_probe_sampling_variance_minimization_' 'Viriyothai2009.exr'))) Y = RGB_luminance(image, colourspace.primaries, colourspace.whitepoint) regions = find_regions_variance_minimization_Viriyothai2009(Y, n=4) np.testing.assert_almost_equal( highlight_regions_variance_minimization(image, regions), read_image( str( os.path.join( SAMPLING_DIRECTORY, 'tests_highlight_regions_variance_minimization.exr'))), decimal=7)
def test_absolute_luminance_calibration_Lagarde2016(self): """ Tests :func:`colour_hdri.calibration.absolute_luminance.\ absolute_luminance_calibration_Lagarde2016` definition. """ # Unity Technologies. (2016). Treasure Island - white balanced.exr. # Retrieved August 30, 2016, from http://blog.selfshadow.com/\ # publications/s2016-shading-course/unity/supplemental/\ # Treasure Island - white balanced.exr reference_exr_file = read_image( str( os.path.join(UNITY_001_DIRECTORY, 'Unity_Treasure_Island_White_Balanced.exr'))) test_exr_file = read_image( str( os.path.join( CALIBRATION_DIRECTORY, 'Unity_Treasure_Island_White_Balanced_Absolute.exr'))) np.testing.assert_allclose(absolute_luminance_calibration_Lagarde2016( reference_exr_file, 51000), test_exr_file, rtol=0.0000001, atol=0.0000001)
def docs(ctx, plots=True, html=True, pdf=True): """ Builds the documentation. Parameters ---------- ctx : invoke.context.Context Context. plots : bool, optional Whether to generate the documentation plots. html : bool, optional Whether to build the *HTML* documentation. pdf : bool, optional Whether to build the *PDF* documentation. Returns ------- bool Task success. """ if plots: temporary_directory = tempfile.mkdtemp() test_directory = os.path.join('docs', '_static') reference_directory = os.path.join(temporary_directory, '_static') try: shutil.copytree(test_directory, reference_directory) similar_plots = [] with ctx.cd('utilities'): message_box('Generating plots...') ctx.run('./generate_plots.py') png_files = glob.glob('{0}/*.png'.format(reference_directory)) for reference_png_file in png_files: test_png_file = os.path.join( test_directory, os.path.basename(reference_png_file)) psnr = metric_psnr( read_image(str(reference_png_file))[::3, ::3], read_image(str(test_png_file))[::3, ::3]) if psnr > 70: similar_plots.append(test_png_file) with ctx.cd('docs/_static'): for similar_plot in similar_plots: ctx.run('git checkout -- {0}'.format( os.path.basename(similar_plot))) finally: shutil.rmtree(temporary_directory) with ctx.prefix('export COLOUR_SCIENCE_DOCUMENTATION_BUILD=True'): with ctx.cd('docs'): if html: message_box('Building "HTML" documentation...') ctx.run('make html') if pdf: message_box('Building "PDF" documentation...') ctx.run('make latexpdf')
def test_convert_dng_files_to_intermediate_files(self): """ Tests :func:`colour_hdri.process.adobe_dng.\ convert_dng_files_to_intermediate_files` definition. """ reference_dng_files = sorted(filter_files(PROCESS_DIRECTORY, ('dng', ))) tests_dng_files = [ os.path.join(self._temporary_directory, os.path.basename(reference_dng_file)) for reference_dng_file in reference_dng_files ] for reference_dng_file, tests_dng_file in zip(reference_dng_files, tests_dng_files): shutil.copyfile(reference_dng_file, tests_dng_file) reference_zip_files = sorted(filter_files(PROCESS_DIRECTORY, ('zip', ))) for reference_zip_file in reference_zip_files: with zipfile.ZipFile(reference_zip_file) as zip_file: tiff_file_name = os.path.basename(reference_zip_file).replace( '.zip', '') with open( os.path.join(self._temporary_directory, tiff_file_name), 'wb') as reference_tiff_file: reference_tiff_file.write(zip_file.read(tiff_file_name)) reference_tiff_files = sorted( filter_files(self._temporary_directory, ('tiff', ))) # for reference_tiff_file in reference_tiff_files: # os.chdir(os.path.dirname(reference_tiff_file)) # with zipfile.ZipFile( # '{0}.zip'.format(reference_tiff_file), # mode='w') as zip_file: # zip_file.write( # os.path.basename(reference_tiff_file), # compress_type=zipfile.ZIP_DEFLATED) # os.remove(reference_tiff_file) test_tiff_files = sorted( convert_dng_files_to_intermediate_files(tests_dng_files, self._temporary_directory)) for test_tiff_file, reference_tiff_file in zip(test_tiff_files, reference_tiff_files): np.testing.assert_almost_equal(read_image(str(test_tiff_file)), read_image( str(reference_tiff_file)), decimal=7)
def test_demosaicing_CFA_Bayer_bilinear(self): """ Tests :func:`colour_demosaicing.bayer.demosaicing.bilinear.\ demosaicing_CFA_Bayer_bilinear` definition. """ for pattern in ('RGGB', 'BGGR', 'GRBG', 'GBRG'): CFA = os.path.join(BAYER_DIRECTORY, 'Lighthouse_CFA_{0}.exr') RGB = os.path.join(BAYER_DIRECTORY, 'Lighthouse_Bilinear_{0}.exr') np.testing.assert_almost_equal( demosaicing_CFA_Bayer_bilinear( read_image(str(CFA.format(pattern))), pattern), read_image(str(RGB.format(pattern))), decimal=7)
def test_mosaicing_CFA_Bayer(self): """ Tests :func:`colour_demosaicing.bayer.mosaicing.mosaicing_CFA_Bayer` definition. """ image = read_image(str(os.path.join(BAYER_DIRECTORY, 'Lighthouse.exr'))) for pattern in ('RGGB', 'BGGR', 'GRBG', 'GBRG'): CFA = os.path.join(BAYER_DIRECTORY, 'Lighthouse_CFA_{0}.exr') np.testing.assert_almost_equal(mosaicing_CFA_Bayer(image, pattern), read_image(str( CFA.format(pattern))), decimal=7)
def test_extract_colour_checkers_segmentation(self): """ Define :func:`colour_checker_detection.detection.segmentation.\ extract_colour_checkers_segmentation` definition unit tests methods. """ colour_checkers_shapes = np.array([ [(209, 310, 3)], [(462, 696, 3)], [(307, 462, 3)], [(285, 426, 3)], [(104, 155, 3)], [(241, 357, 3)], ]) for i, png_file in enumerate(PNG_FILES): np.testing.assert_allclose( [ colour_checker.shape for colour_checker in extract_colour_checkers_segmentation( read_image(png_file)) ], colour_checkers_shapes[i], rtol=5, atol=5, )
def load_image(path, decoding_cctf='sRGB'): """ Loads the image at given path and caches it in `IMAGE_CACHE` cache. If the image is already cached, it is returned directly. Parameters ---------- path : unicode Image path. decoding_cctf : unicode, optional Decoding colour component transfer function (Decoding CCTF) / electro-optical transfer function (EOTF / EOCF) that maps an :math:`R'G'B'` video component signal value to tristimulus values at the display. Returns ------- ndarray Image as a ndarray. """ is_linear_image = os.path.splitext(path)[-1].lower() in LINEAR_FILE_FORMATS key = path if is_linear_image else '{0}-{1}'.format(path, decoding_cctf) RGB = IMAGE_CACHE.get(key) if RGB is None: RGB = read_image(path) if not is_linear_image: RGB = DECODING_CCTFS[decoding_cctf](RGB) IMAGE_CACHE.set(key, RGB) return RGB
def get_sampler(in_xdata, in_image_path, out_image_name, ctl_list): out_image_path = os.path.join(IO_DIRECTORY, out_image_name) ctlrender(in_image_path, out_image_path, ctl_list) ydata = colour.read_image( out_image_path, method='Imageio')[..., 0].ravel() # flatten to 1D array return colour.LinearInterpolator(in_xdata, ydata)
def test_adjust_image(self): """ Defines :func:`colour_checker_detection.detection.segmentation.\ adjust_image` definition unit tests methods. """ image = adjust_image(read_image(PNG_FILES[0])) self.assertEqual(image.shape[1], WORKING_WIDTH)
def test_mosaicing_CFA_Bayer(self): """ Tests :func:`colour_demosaicing.bayer.mosaicing.mosaicing_CFA_Bayer` definition. """ image = colour.read_image( str(os.path.join(BAYER_DIRECTORY, 'Lighthouse.exr'))) for pattern in ('RGGB', 'BGGR', 'GRBG', 'GBRG'): np.testing.assert_almost_equal( mosaicing_CFA_Bayer(image, pattern), colour.read_image( str(os.path.join( BAYER_DIRECTORY, 'Lighthouse_CFA_{0}.exr'.format(pattern)))), decimal=7)
def apply_lut(self, context, temp_image, temp_pass): from colour import read_LUT from colour import write_image, read_image lut3d = read_LUT(context.scene["lut_import_pass"]) luminance_map_img = lut3d.apply(read_image(temp_image)) write_image(luminance_map_img, temp_pass, bit_depth='uint8') new_image = bpy.data.images.load(temp_pass, check_existing=True) new_image.reload()
def test_highlight_regions_variance_minimization(self): """ Tests :func:`colour_hdri.sampling.variance_minimization.\ highlight_regions_variance_minimization` definition. """ image = read_image(str(os.path.join( SAMPLING_DIRECTORY, 'tests_light_probe_sampling_variance_minimization.exr'))) Y = np.dot(image, DEFAULT_LUMINANCE_FACTORS) regions = find_regions_variance_minimization(Y, n=4) np.testing.assert_almost_equal( highlight_regions_variance_minimization(image, regions), read_image(str(os.path.join( SAMPLING_DIRECTORY, 'tests_highlight_regions_variance_minimization.exr'))), decimal=7)
def test_demosaicing_CFA_Bayer_Malvar2004(self): """ Tests :func:`colour_demosaicing.bayer.demosaicing.malvar2004.\ demosaicing_CFA_Bayer_Malvar2004` definition. """ for pattern in ('RGGB', 'BGGR', 'GRBG', 'GBRG'): np.testing.assert_almost_equal( demosaicing_CFA_Bayer_Malvar2004( colour.read_image( str(os.path.join( BAYER_DIRECTORY, 'Lighthouse_CFA_{0}.exr'.format(pattern)))), pattern), colour.read_image( str(os.path.join( BAYER_DIRECTORY, 'Lighthouse_Malvar2004_{0}.exr'.format(pattern)))), decimal=7)
def test_highlights_recovery_blend(self): """ Tests :func:`colour_hdri.recovery.highlights.highlights_recovery_blend` definition. """ multipliers = np.array([2.42089718, 1.00000000, 1.54687415]) multipliers /= np.max(multipliers) XYZ_to_camera_matrix = np.array([ [0.47160000, 0.06030000, -0.08300000], [-0.77980000, 1.54740000, 0.24800000], [-0.14960000, 0.19370000, 0.66510000]]) reference_raw_file = RAW_IMAGES[1] test_raw_file = os.path.join( self.__temporary_directory, os.path.basename(reference_raw_file)) shutil.copyfile(reference_raw_file, test_raw_file) command = [RAW_CONVERTER] + shlex.split( RAW_D_CONVERSION_ARGUMENTS.format(test_raw_file), posix=(False if platform.system() in ("Windows", "Microsoft") else True)) subprocess.call(command) test_tiff_file = read_image( str(re.sub('\.CR2$', '.tiff', test_raw_file))) test_tiff_file *= multipliers test_tiff_file = highlights_recovery_blend( test_tiff_file, multipliers) test_tiff_file = camera_space_to_sRGB( test_tiff_file, XYZ_to_camera_matrix) reference_tiff_file = read_image(str(os.path.join( RECOVERY_DIRECTORY, os.path.basename(re.sub('\.CR2$', '.exr', test_raw_file))))) np.testing.assert_almost_equal( test_tiff_file[::10, ::10, :], reference_tiff_file, decimal=7)
def get_test_image(proxy=True): path = get_dependency_local_path(key) im = read_image(path)[..., 0:3] # if proxy: # proxy_res = (1920, 1080) # return ( # Image.fromarray(img) # .thumbnail(size=proxy_res, resample=Image.BICUBIC) # ) return im
def test_demosaicing_CFA_Bayer_Malvar2004(self): """ Tests :func:`colour_demosaicing.bayer.demosaicing.malvar2004.\ demosaicing_CFA_Bayer_Malvar2004` definition. """ for pattern in ('RGGB', 'BGGR', 'GRBG', 'GBRG'): np.testing.assert_almost_equal( demosaicing_CFA_Bayer_Malvar2004( colour.read_image( str( os.path.join( BAYER_DIRECTORY, 'Lighthouse_CFA_{0}.exr'.format(pattern)))), pattern), colour.read_image( str( os.path.join( BAYER_DIRECTORY, 'Lighthouse_Malvar2004_{0}.exr'.format(pattern)))), decimal=7)
def test_masks_CFA_Bayer(self): """ Tests :func:`colour_demosaicing.bayer.masks.masks_CFA_Bayer` definition. """ for pattern in ('RGGB', 'BGGR', 'GRBG', 'GBRG'): mask = os.path.join(BAYER_DIRECTORY, '{0}_Masks.exr') np.testing.assert_almost_equal( tstack(masks_CFA_Bayer((8, 8), pattern)), read_image(str(mask.format(pattern))), decimal=7)
def apply_lut(self, context, temp_image, temp_pass): # パスを追加 path_roaming = os.getenv('APPDATA') + "\\Python" for ver in os.listdir(path_roaming): sys.path.append(path_roaming + "\\" + ver + "\\site-packages\\") from colour import read_LUT from colour import write_image, read_image lut3d = read_LUT(context.scene["lut_import_pass"]) luminance_map_img = lut3d.apply(read_image(temp_image)) write_image(luminance_map_img, temp_pass, bit_depth='uint8') new_image = bpy.data.images.load(temp_pass, check_existing=True) new_image.reload()
def test_convert_raw_files_to_dng_files(self): """ Tests :func:`colour_hdri.process.adobe_dng.\ convert_raw_files_to_dng_files` definition. """ if platform.system() not in ('Windows', 'Microsoft', 'Darwin'): # *Adobe DNG Converter* is not available on Linux, thus we skip # that unit test. return reference_dng_files = sorted(filter_files(PROCESS_DIRECTORY, ('dng', ))) test_dng_files = sorted( convert_raw_files_to_dng_files(RAW_IMAGES, self._temporary_directory)) for test_dng_file, reference_dng_file in zip(test_dng_files, reference_dng_files): np.testing.assert_almost_equal(read_image(str(test_dng_file)), read_image(str(reference_dng_file)), decimal=7)
def test_adjust_image(self): """ Defines :func:`colour_checker_detection.detection.segmentation.\ adjust_image` definition unit tests methods. """ # Skipping unit test when "png" files are missing, e.g. when testing # the distributed "Python" package. if len(PNG_FILES) > 0: return image = adjust_image(read_image(PNG_FILES[0])) self.assertEqual(image.shape[1], WORKING_WIDTH)
def test_masks_CFA_Bayer(self): """ Tests :func:`colour_demosaicing.bayer.masks.masks_CFA_Bayer` definition. """ for pattern in ('RGGB', 'BGGR', 'GRBG', 'GBRG'): np.testing.assert_almost_equal( colour.tstack(masks_CFA_Bayer((8, 8), pattern)), colour.read_image( str(os.path.join(BAYER_DIRECTORY, '{0}_Masks.exr'.format(pattern)))), decimal=7)
def test_as_8_bit_BGR_image(self): """ Defines :func:`colour_checker_detection.detection.segmentation.\ as_8_bit_BGR_image` definition unit tests methods. """ image_i = read_image(PNG_FILES[0]) image_o = as_8_bit_BGR_image(image_i) self.assertEqual(image_o.dtype, np.uint8) np.testing.assert_almost_equal(image_o[16, 16, ...], (oetf_sRGB(image_i[16, 16, ::-1]) * 255).astype(np.uint8))
def test_convert_raw_files_to_dng_files(self): """ Tests :func:`colour_hdri.process.conversion.\ convert_raw_files_to_dng_files` definition. """ if platform.system() not in ('Windows', 'Microsoft', 'Darwin'): # *Adobe DNG Converter* is not available on Linux, thus we skip # that unit test. return reference_dng_files = sorted(filter_files( PROCESS_DIRECTORY, ('dng',))) test_dng_files = sorted(convert_raw_files_to_dng_files( RAW_IMAGES, self.__temporary_directory)) for test_dng_file, reference_dng_file in zip( test_dng_files, reference_dng_files): np.testing.assert_almost_equal( read_image(str(test_dng_file)), read_image(str(reference_dng_file)), decimal=7)
def unpack_exr(exr_image, bit_depth=16): #open the EXR file using OpenEXR python wrapper im = OpenEXR.InputFile(exr_image) try: str(im.header()['acesImageContainerFlag']) except KeyError: print( 'EXR file does not contain ACES container flag and therefore does not meet the SMPTE standards' ) #ACES Chromaticities #if the file does not contain the correct red, green, blue, and white point chromaticities, # then the EXR file is not an ACES file and cannot continue if str(im.header()['chromaticities'].red ) != '(0.7347000241279602, 0.2653000056743622)': print('ERROR') raise ValueError('Red Chromaticities are bad') if str(im.header()['chromaticities'].green) != '(0.0, 1.0)': raise ValueError('Green Chromaticities are bad') if str(im.header()['chromaticities'].blue ) != '(9.999999747378752e-05, -0.07699999958276749)': raise ValueError('Blue Chromaticities are bad') if str(im.header()['chromaticities'].white ) != '(0.3216800093650818, 0.3376699984073639)': raise ValueError(' White point Chromaticities are bad') #if file is an ACES EXR file, the find the red, green, and blue channels from the image (r, g, b) = im.channels("RGB") #find the image size information from the header dw = im.header()['dataWindow'] size = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1) #extract the red, green, and blue color record, change to floating point number and # reshape to the size of the image red = numpy.reshape(numpy.fromstring(r, dtype=numpy.float16), (size[1], size[0])) green = numpy.reshape(numpy.fromstring(g, dtype=numpy.float16), (size[1], size[0])) blue = numpy.reshape(numpy.fromstring(b, dtype=numpy.float16), (size[1], size[0])) #stack the red, green, and blue record to create the image array image = numpy.stack((red, green, blue), axis=-1) image_io = read_image(exr_image) return image, image_io
def read_data(self): """ Reads image pixel data at :attr:`Image.path` attribute. Returns ------- ndarray Image pixel data. """ LOGGER.info('Reading "{0}" image.'.format(self._path)) self.data = read_image(str(self._path)) return self.data
def test_find_regions_variance_minimization_Viriyothai2009(self): """ Tests :func:`colour_hdri.sampling.variance_minimization.\ find_regions_variance_minimization_Viriyothai2009` definition. """ colourspace = RGB_COLOURSPACES['sRGB'] image = read_image( str( os.path.join( SAMPLING_DIRECTORY, 'tests_light_probe_sampling_variance_minimization_' 'Viriyothai2009.exr'))) Y = RGB_luminance(image, colourspace.primaries, colourspace.whitepoint) regions = find_regions_variance_minimization_Viriyothai2009(Y, n=1) self.assertListEqual( regions, [(0, 256, 0, 156), (0, 256, 156, 256)]) # yapf: disable regions = find_regions_variance_minimization_Viriyothai2009(Y, n=2) self.assertListEqual( regions, [(0, 97, 0, 156), (97, 256, 0, 156), (0, 100, 156, 256), (100, 256, 156, 256)]) # yapf: disable regions = find_regions_variance_minimization_Viriyothai2009(Y, n=4) self.assertListEqual( regions, [(0, 39, 0, 91), (39, 97, 0, 91), (0, 39, 91, 156), (39, 97, 91, 156), (97, 159, 0, 92), (97, 159, 92, 156), (159, 256, 0, 93), (159, 256, 93, 156), (0, 42, 156, 216), (42, 100, 156, 216), (0, 44, 216, 256), (44, 100, 216, 256), (100, 163, 156, 215), (100, 163, 215, 256), (163, 256, 156, 216), (163, 256, 216, 256)]) # yapf: disable
def test_adjust_image(self): """ Define :func:`colour_checker_detection.detection.segmentation.\ adjust_image` definition unit tests methods. """ # Skipping unit test when "png" files are missing, e.g. when testing # the distributed "Python" package. if len(PNG_FILES) == 0: return image = adjust_image(read_image(PNG_FILES[0]), 1440) self.assertEqual( image.shape[1], SETTINGS_SEGMENTATION_COLORCHECKER_CLASSIC["working_width"], )
def test_crop_and_level_image_with_rectangle(self): """ Defines :func:`colour_checker_detection.detection.segmentation.\ crop_and_level_image_with_rectangle` definition unit tests methods. """ image = as_8_bit_BGR_image(adjust_image(read_image(PNG_FILES[0]))) rectangle = ( (832.99865723, 473.05020142), (209.08610535, 310.13061523), -88.35559082, ) np.testing.assert_array_equal( crop_and_level_image_with_rectangle(image, rectangle).shape, (209, 310, 3), )
def test_as_8_bit_BGR_image(self): """ Defines :func:`colour_checker_detection.detection.segmentation.\ as_8_bit_BGR_image` definition unit tests methods. """ # Skipping unit test when "png" files are missing, e.g. when testing # the distributed "Python" package. if len(PNG_FILES) > 0: return image_i = read_image(PNG_FILES[0]) image_o = as_8_bit_BGR_image(image_i) self.assertEqual(image_o.dtype, np.uint8) np.testing.assert_almost_equal(image_o[16, 16, ...], (cctf_encoding(image_i[16, 16, ::-1]) * 255).astype(np.uint8))
def test_find_regions_variance_minimization(self): """ Tests :func:`colour_hdri.sampling.variance_minimization.\ find_regions_variance_minimization` definition. """ image = read_image(str(os.path.join( SAMPLING_DIRECTORY, 'tests_light_probe_sampling_variance_minimization.exr'))) Y = np.dot(image, DEFAULT_LUMINANCE_FACTORS) regions = find_regions_variance_minimization(Y, n=1) self.assertListEqual( regions, [(0, 256, 0, 156), (0, 256, 156, 256)]) regions = find_regions_variance_minimization(Y, n=2) self.assertListEqual( regions, [(0, 97, 0, 156), (97, 256, 0, 156), (0, 100, 156, 256), (100, 256, 156, 256)]) regions = find_regions_variance_minimization(Y, n=4) self.assertListEqual( regions, [(0, 39, 0, 91), (39, 97, 0, 91), (0, 39, 91, 156), (39, 97, 91, 156), (97, 159, 0, 92), (97, 159, 92, 156), (159, 256, 0, 93), (159, 256, 93, 156), (0, 42, 156, 216), (42, 100, 156, 216), (0, 44, 216, 256), (44, 100, 216, 256), (100, 163, 156, 215), (100, 163, 215, 256), (163, 256, 156, 216), (163, 256, 216, 256)])
def read_data(self, cctf_decoding=None): """ Reads image pixel data at :attr:`Image.path` attribute. Parameters ---------- cctf_decoding : object, optional Decoding colour component transfer function (Decoding CCTF) or electro-optical transfer function (EOTF / EOCF). Returns ------- ndarray Image pixel data. """ logging.info('Reading "{0}" image.'.format(self._path)) self.data = read_image(str(self._path)) if cctf_decoding is not None: self.data = cctf_decoding(self.data) return self.data
def test_crop_and_level_image_with_rectangle(self): """ Defines :func:`colour_checker_detection.detection.segmentation.\ crop_and_level_image_with_rectangle` definition unit tests methods. """ # Skipping unit test when "png" files are missing, e.g. when testing # the distributed "Python" package. if len(PNG_FILES) > 0: return image = as_8_bit_BGR_image(adjust_image(read_image(PNG_FILES[0]))) rectangle = ( (832.99865723, 473.05020142), (209.08610535, 310.13061523), -88.35559082, ) np.testing.assert_array_equal( crop_and_level_image_with_rectangle(image, rectangle).shape, (209, 310, 3), )
def get_test_image(): key = st.selectbox( label="Test Image", options=["Marcie 4K", "CLF Test Image", "Upload EXR"], ) upload_image_placeholder = st.empty() image_scale = st.slider( label="Downsize Image", min_value=1, max_value=10, value=3, step=1, ) if key == "Upload EXR": img = upload_image_placeholder.file_uploader(label="Input Image", type=[".exr"]) else: img = get_dependency_local_path(key) return downsize_image( read_image(img.read() if hasattr(img, "read") else img), factor=image_scale)
def fraunhofer_lines_plot(image=SUN_SPECTRUM_IMAGE): """ Plots the Fraunhofer lines of given image. Parameters ---------- image : unicode Path to read the image from. Returns ------- bool Definition success. """ spectrum = RGB_spectrum(read_image(image), FRAUNHOFER_LINES_PUBLISHED, FRAUNHOFER_LINES_MEASURED) height = len(spectrum.R.values) / 8 spd = luminance_spd(spectrum).normalise(height) pylab.title('The Solar Spectrum - Fraunhofer Lines') wavelengths = spectrum.wavelengths input, output = min(wavelengths), max(wavelengths) pylab.imshow(sRGB_COLOURSPACE.OECF( np.dstack([spectrum.R.values, spectrum.G.values, spectrum.B.values])), extent=[input, output, 0, height]) pylab.plot(spd.wavelengths, spd.values, color='black', linewidth=1) fraunhofer_wavelengths = np.array( sorted(FRAUNHOFER_LINES_PUBLISHED.values())) fraunhofer_wavelengths = fraunhofer_wavelengths[ np.where(np.logical_and(fraunhofer_wavelengths >= input, fraunhofer_wavelengths <= output))] fraunhofer_lines_labels = [ tuple(FRAUNHOFER_LINES_PUBLISHED.keys())[ tuple(FRAUNHOFER_LINES_PUBLISHED.values()).index(i)] for i in fraunhofer_wavelengths] y0, y1 = 0, height * .5 for i, label in enumerate(fraunhofer_lines_labels): # Trick to cluster siblings fraunhofer lines. from_siblings = False for pattern, (first, siblings, specific_label) in FRAUNHOFER_LINES_CLUSTERED.items(): if re.match(pattern, label): if label in siblings: from_siblings = True label = specific_label break power = bisect.bisect_left(wavelengths, fraunhofer_wavelengths[i]) scale = (spd.get(wavelengths[power]) / height) is_large_line = label in FRAUNHOFER_LINES_NOTABLE pylab.vlines(fraunhofer_wavelengths[i], y0, y1 * scale, linewidth=2 if is_large_line else 1) pylab.vlines(fraunhofer_wavelengths[i], y0, height, linewidth=2 if is_large_line else 1, alpha=0.075) if not from_siblings: pylab.text(fraunhofer_wavelengths[i], y1 * scale + (y1 * 0.025), label, clip_on=True, ha='center', va='bottom', fontdict={'size': 'large' if is_large_line else'small'}) r = lambda x: int(x / 100) * 100 matplotlib.pyplot.xticks(np.arange(r(input), r(output * 1.5), 20)) settings = {'x_tighten': True, 'y_tighten': True, 'x_label': u'Wavelength λ (nm)', 'y_label': False, 'legend': False, 'limits': [input, output, 0, height], 'y_ticker': True, 'grid': True} boundaries(**settings) decorate(**settings) return display(**settings)
import numpy as np import os import colour from colour.plotting import (colour_style, plot_cvd_simulation_Machado2009, plot_image) 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.oetf_reverse(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(ISHIHARA_CBT_3_IMAGE, 'Normal Trichromat', label_colour='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',
def generate_documentation_plots(output_directory): """ Generates documentation plots. Parameters ---------- output_directory : unicode Output directory. """ colour.utilities.filter_warnings() colour_style() np.random.seed(0) # ************************************************************************* # "README.rst" # ************************************************************************* arguments = { 'tight_layout': True, 'transparent_background': True, 'filename': os.path.join(output_directory, 'Examples_Plotting_Visible_Spectrum.png') } plot_visible_spectrum('CIE 1931 2 Degree Standard Observer', **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_Illuminant_F1_SD.png') plot_single_illuminant_sd('FL1', **arguments) arguments['filename'] = os.path.join(output_directory, 'Examples_Plotting_Blackbodies.png') blackbody_sds = [ colour.sd_blackbody(i, colour.SpectralShape(0, 10000, 10)) for i in range(1000, 15000, 1000) ] plot_multi_sds( blackbody_sds, y_label='W / (sr m$^2$) / m', use_sds_colours=True, normalise_sds_colours=True, legend_location='upper right', bounding_box=(0, 1250, 0, 2.5e15), **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_Cone_Fundamentals.png') plot_single_cmfs( 'Stockman & Sharpe 2 Degree Cone Fundamentals', y_label='Sensitivity', bounding_box=(390, 870, 0, 1.1), **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_Luminous_Efficiency.png') sd_mesopic_luminous_efficiency_function = ( colour.sd_mesopic_luminous_efficiency_function(0.2)) plot_multi_sds( (sd_mesopic_luminous_efficiency_function, colour.PHOTOPIC_LEFS['CIE 1924 Photopic Standard Observer'], colour.SCOTOPIC_LEFS['CIE 1951 Scotopic Standard Observer']), y_label='Luminous Efficiency', legend_location='upper right', y_tighten=True, margins=(0, 0, 0, .1), **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_BabelColor_Average.png') plot_multi_sds( colour.COLOURCHECKERS_SDS['BabelColor Average'].values(), use_sds_colours=True, title=('BabelColor Average - ' 'Spectral Distributions'), **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_ColorChecker_2005.png') plot_single_colour_checker( 'ColorChecker 2005', text_parameters={'visible': False}, **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_Chromaticities_Prediction.png') plot_corresponding_chromaticities_prediction(2, 'Von Kries', 'Bianco', **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_CCT_CIE_1960_UCS_Chromaticity_Diagram.png') plot_planckian_locus_in_chromaticity_diagram_CIE1960UCS(['A', 'B', 'C'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_Chromaticities_CIE_1931_Chromaticity_Diagram.png') RGB = np.random.random((32, 32, 3)) plot_RGB_chromaticities_in_chromaticity_diagram_CIE1931( RGB, 'ITU-R BT.709', colourspaces=['ACEScg', 'S-Gamut'], show_pointer_gamut=True, **arguments) arguments['filename'] = os.path.join(output_directory, 'Examples_Plotting_CRI.png') plot_single_sd_colour_rendering_index_bars(colour.ILLUMINANTS_SDS['FL2'], **arguments) # ************************************************************************* # Documentation # ************************************************************************* arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_CVD_Simulation_Machado2009.png') plot_cvd_simulation_Machado2009(RGB, **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Colour_Checker.png') plot_single_colour_checker('ColorChecker 2005', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Colour_Checkers.png') plot_multi_colour_checkers(['ColorChecker 1976', 'ColorChecker 2005'], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Single_SD.png') data = { 500: 0.0651, 520: 0.0705, 540: 0.0772, 560: 0.0870, 580: 0.1128, 600: 0.1360 } sd = colour.SpectralDistribution(data, name='Custom') plot_single_sd(sd, **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Multi_SDs.png') data_1 = { 500: 0.004900, 510: 0.009300, 520: 0.063270, 530: 0.165500, 540: 0.290400, 550: 0.433450, 560: 0.594500 } data_2 = { 500: 0.323000, 510: 0.503000, 520: 0.710000, 530: 0.862000, 540: 0.954000, 550: 0.994950, 560: 0.995000 } spd1 = colour.SpectralDistribution(data_1, name='Custom 1') spd2 = colour.SpectralDistribution(data_2, name='Custom 2') plot_multi_sds([spd1, spd2], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Single_CMFS.png') plot_single_cmfs('CIE 1931 2 Degree Standard Observer', **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Multi_CMFS.png') cmfs = ('CIE 1931 2 Degree Standard Observer', 'CIE 1964 10 Degree Standard Observer') plot_multi_cmfs(cmfs, **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Illuminant_SD.png') plot_single_illuminant_sd('A', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Illuminant_SDs.png') plot_multi_illuminant_sds(['A', 'B', 'C'], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Visible_Spectrum.png') plot_visible_spectrum(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Lightness_Function.png') plot_single_lightness_function('CIE 1976', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Lightness_Functions.png') plot_multi_lightness_functions(['CIE 1976', 'Wyszecki 1963'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Luminance_Function.png') plot_single_luminance_function('CIE 1976', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Luminance_Functions.png') plot_multi_luminance_functions(['CIE 1976', 'Newhall 1943'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Blackbody_Spectral_Radiance.png') plot_blackbody_spectral_radiance( 3500, blackbody='VY Canis Major', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Blackbody_Colours.png') plot_blackbody_colours(colour.SpectralShape(150, 12500, 50), **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Colour_Swatch.png') RGB = ColourSwatch(RGB=(0.32315746, 0.32983556, 0.33640183)) plot_single_colour_swatch(RGB, **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Colour_Swatches.png') RGB_1 = ColourSwatch(RGB=(0.45293517, 0.31732158, 0.26414773)) RGB_2 = ColourSwatch(RGB=(0.77875824, 0.57726450, 0.50453169)) plot_multi_colour_swatches([RGB_1, RGB_2], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Single_Function.png') plot_single_function(lambda x: x ** (1 / 2.2), **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Multi_Functions.png') functions = { 'Gamma 2.2': lambda x: x ** (1 / 2.2), 'Gamma 2.4': lambda x: x ** (1 / 2.4), 'Gamma 2.6': lambda x: x ** (1 / 2.6), } plot_multi_functions(functions, **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Image.png') path = os.path.join(colour.__path__[0], '..', 'docs', '_static', 'Logo_Medium_001.png') plot_image(colour.read_image(str(path)), **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Corresponding_Chromaticities_Prediction.png') plot_corresponding_chromaticities_prediction(1, 'Von Kries', 'CAT02', **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Spectral_Locus.png') plot_spectral_locus(spectral_locus_colours='RGB', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Chromaticity_Diagram_Colours.png') plot_chromaticity_diagram_colours(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Chromaticity_Diagram.png') plot_chromaticity_diagram(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Chromaticity_Diagram_CIE1931.png') plot_chromaticity_diagram_CIE1931(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Chromaticity_Diagram_CIE1960UCS.png') plot_chromaticity_diagram_CIE1960UCS(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Chromaticity_Diagram_CIE1976UCS.png') plot_chromaticity_diagram_CIE1976UCS(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_SDs_In_Chromaticity_Diagram.png') A = colour.ILLUMINANTS_SDS['A'] D65 = colour.ILLUMINANTS_SDS['D65'] plot_sds_in_chromaticity_diagram([A, D65], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_SDs_In_Chromaticity_Diagram_CIE1931.png') plot_sds_in_chromaticity_diagram_CIE1931([A, D65], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_SDs_In_Chromaticity_Diagram_CIE1960UCS.png') plot_sds_in_chromaticity_diagram_CIE1960UCS([A, D65], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_SDs_In_Chromaticity_Diagram_CIE1976UCS.png') plot_sds_in_chromaticity_diagram_CIE1976UCS([A, D65], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Pointer_Gamut.png') plot_pointer_gamut(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_In_Chromaticity_Diagram.png') plot_RGB_colourspaces_in_chromaticity_diagram( ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_In_Chromaticity_Diagram_CIE1931.png') plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931( ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_In_' 'Chromaticity_Diagram_CIE1960UCS.png') plot_RGB_colourspaces_in_chromaticity_diagram_CIE1960UCS( ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_In_' 'Chromaticity_Diagram_CIE1976UCS.png') plot_RGB_colourspaces_in_chromaticity_diagram_CIE1976UCS( ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Chromaticities_In_' 'Chromaticity_Diagram_Plot.png') RGB = np.random.random((128, 128, 3)) plot_RGB_chromaticities_in_chromaticity_diagram(RGB, 'ITU-R BT.709', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Chromaticities_In_' 'Chromaticity_Diagram_CIE1931.png') plot_RGB_chromaticities_in_chromaticity_diagram_CIE1931( RGB, 'ITU-R BT.709', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Chromaticities_In_' 'Chromaticity_Diagram_CIE1960UCS.png') plot_RGB_chromaticities_in_chromaticity_diagram_CIE1960UCS( RGB, 'ITU-R BT.709', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Chromaticities_In_' 'Chromaticity_Diagram_CIE1976UCS.png') plot_RGB_chromaticities_in_chromaticity_diagram_CIE1976UCS( RGB, 'ITU-R BT.709', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_Chromaticity_Diagram.png') plot_ellipses_MacAdam1942_in_chromaticity_diagram(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_' 'Chromaticity_Diagram_CIE1931.png') plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1931(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_' 'Chromaticity_Diagram_CIE1960UCS.png') plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1960UCS(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_' 'Chromaticity_Diagram_CIE1976UCS.png') plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1976UCS(**arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Single_CCTF.png') plot_single_cctf('ITU-R BT.709', **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Multi_CCTFs.png') plot_multi_cctfs(['ITU-R BT.709', 'sRGB'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Munsell_Value_Function.png') plot_single_munsell_value_function('ASTM D1535-08', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Munsell_Value_Functions.png') plot_multi_munsell_value_functions(['ASTM D1535-08', 'McCamy 1987'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_SD_Rayleigh_Scattering.png') plot_single_sd_rayleigh_scattering(**arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_The_Blue_Sky.png') plot_the_blue_sky(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Colour_Quality_Bars.png') illuminant = colour.ILLUMINANTS_SDS['FL2'] light_source = colour.LIGHT_SOURCES_SDS['Kinoton 75P'] light_source = light_source.copy().align(colour.SpectralShape(360, 830, 1)) cqs_i = colour.colour_quality_scale(illuminant, additional_data=True) cqs_l = colour.colour_quality_scale(light_source, additional_data=True) plot_colour_quality_bars([cqs_i, cqs_l], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_SD_Colour_Rendering_Index_Bars.png') illuminant = colour.ILLUMINANTS_SDS['FL2'] plot_single_sd_colour_rendering_index_bars(illuminant, **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_SDs_Colour_Rendering_Indexes_Bars.png') light_source = colour.LIGHT_SOURCES_SDS['Kinoton 75P'] plot_multi_sds_colour_rendering_indexes_bars([illuminant, light_source], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_SD_Colour_Quality_Scale_Bars.png') illuminant = colour.ILLUMINANTS_SDS['FL2'] plot_single_sd_colour_quality_scale_bars(illuminant, **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_SDs_Colour_Quality_Scales_Bars.png') light_source = colour.LIGHT_SOURCES_SDS['Kinoton 75P'] plot_multi_sds_colour_quality_scales_bars([illuminant, light_source], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Planckian_Locus.png') plot_planckian_locus(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Planckian_Locus_In_Chromaticity_Diagram.png') plot_planckian_locus_in_chromaticity_diagram(['A', 'B', 'C'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Planckian_Locus_In_Chromaticity_Diagram_CIE1931.png') plot_planckian_locus_in_chromaticity_diagram_CIE1931(['A', 'B', 'C'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Planckian_Locus_In_Chromaticity_Diagram_CIE1960UCS.png') plot_planckian_locus_in_chromaticity_diagram_CIE1960UCS(['A', 'B', 'C'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_Gamuts.png') plot_RGB_colourspaces_gamuts(['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_Gamuts.png') plot_RGB_colourspaces_gamuts(['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_RGB_Scatter.png') plot_RGB_scatter(RGB, 'ITU-R BT.709', **arguments) # ************************************************************************* # "tutorial.rst" # ************************************************************************* arguments['filename'] = os.path.join(output_directory, 'Tutorial_Visible_Spectrum.png') plot_visible_spectrum(**arguments) arguments['filename'] = os.path.join(output_directory, 'Tutorial_Sample_SD.png') sample_sd_data = { 380: 0.048, 385: 0.051, 390: 0.055, 395: 0.060, 400: 0.065, 405: 0.068, 410: 0.068, 415: 0.067, 420: 0.064, 425: 0.062, 430: 0.059, 435: 0.057, 440: 0.055, 445: 0.054, 450: 0.053, 455: 0.053, 460: 0.052, 465: 0.052, 470: 0.052, 475: 0.053, 480: 0.054, 485: 0.055, 490: 0.057, 495: 0.059, 500: 0.061, 505: 0.062, 510: 0.065, 515: 0.067, 520: 0.070, 525: 0.072, 530: 0.074, 535: 0.075, 540: 0.076, 545: 0.078, 550: 0.079, 555: 0.082, 560: 0.087, 565: 0.092, 570: 0.100, 575: 0.107, 580: 0.115, 585: 0.122, 590: 0.129, 595: 0.134, 600: 0.138, 605: 0.142, 610: 0.146, 615: 0.150, 620: 0.154, 625: 0.158, 630: 0.163, 635: 0.167, 640: 0.173, 645: 0.180, 650: 0.188, 655: 0.196, 660: 0.204, 665: 0.213, 670: 0.222, 675: 0.231, 680: 0.242, 685: 0.251, 690: 0.261, 695: 0.271, 700: 0.282, 705: 0.294, 710: 0.305, 715: 0.318, 720: 0.334, 725: 0.354, 730: 0.372, 735: 0.392, 740: 0.409, 745: 0.420, 750: 0.436, 755: 0.450, 760: 0.462, 765: 0.465, 770: 0.448, 775: 0.432, 780: 0.421 } sd = colour.SpectralDistribution(sample_sd_data, name='Sample') plot_single_sd(sd, **arguments) arguments['filename'] = os.path.join(output_directory, 'Tutorial_SD_Interpolation.png') sd_copy = sd.copy() sd_copy.interpolate(colour.SpectralShape(400, 770, 1)) plot_multi_sds( [sd, sd_copy], bounding_box=[730, 780, 0.25, 0.5], **arguments) arguments['filename'] = os.path.join(output_directory, 'Tutorial_Sample_Swatch.png') sd = colour.SpectralDistribution(sample_sd_data) cmfs = colour.STANDARD_OBSERVERS_CMFS[ 'CIE 1931 2 Degree Standard Observer'] illuminant = colour.ILLUMINANTS_SDS['D65'] with domain_range_scale('1'): XYZ = colour.sd_to_XYZ(sd, cmfs, illuminant) RGB = colour.XYZ_to_sRGB(XYZ) plot_single_colour_swatch( ColourSwatch('Sample', RGB), text_parameters={'size': 'x-large'}, **arguments) arguments['filename'] = os.path.join(output_directory, 'Tutorial_Neutral5.png') patch_name = 'neutral 5 (.70 D)' patch_sd = colour.COLOURCHECKERS_SDS['ColorChecker N Ohta'][patch_name] with domain_range_scale('1'): XYZ = colour.sd_to_XYZ(patch_sd, cmfs, illuminant) RGB = colour.XYZ_to_sRGB(XYZ) plot_single_colour_swatch( ColourSwatch(patch_name.title(), RGB), text_parameters={'size': 'x-large'}, **arguments) arguments['filename'] = os.path.join(output_directory, 'Tutorial_Colour_Checker.png') plot_single_colour_checker( colour_checker='ColorChecker 2005', text_parameters={'visible': False}, **arguments) arguments['filename'] = os.path.join( output_directory, 'Tutorial_CIE_1931_Chromaticity_Diagram.png') xy = colour.XYZ_to_xy(XYZ) plot_chromaticity_diagram_CIE1931(standalone=False) x, y = xy plt.plot(x, y, 'o-', color='white') # Annotating the plot. plt.annotate( patch_sd.name.title(), xy=xy, xytext=(-50, 30), textcoords='offset points', arrowprops=dict(arrowstyle='->', connectionstyle='arc3, rad=-0.2')) render( standalone=True, limits=(-0.1, 0.9, -0.1, 0.9), x_tighten=True, y_tighten=True, **arguments) # ************************************************************************* # "basics.rst" # ************************************************************************* arguments['filename'] = os.path.join(output_directory, 'Basics_Logo_Small_001_CIE_XYZ.png') RGB = colour.read_image( os.path.join(output_directory, 'Logo_Small_001.png'))[..., 0:3] XYZ = colour.sRGB_to_XYZ(RGB) colour.plotting.plot_image( XYZ, text_parameters={'text': 'sRGB to XYZ'}, **arguments)
import numpy as np import os import colour from colour.plotting import (colour_style, plot_cvd_simulation_Machado2009, plot_image) 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.oetf_reverse( 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.oetf(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(
def main(): """ Starts the application. Return ------ bool Definition success. """ arguments = command_line_arguments() if arguments.version: print("{0} - {1}".format(__application_name__, __version__)) return True settings = json.load(open(SETTINGS_FILE)) if arguments.settings_file is not None: assert os.path.exists(arguments.settings_file), '"{0}" file doesn\'t exists!'.format(arguments.settings_file) settings.update(json.load(open(arguments.settings_file))) input_linearity = arguments.input_linearity.lower() if input_linearity == "linear": input_linear = True elif input_linearity == "oecf": input_linear = False else: input_extension = os.path.splitext(arguments.input_image)[1].lower() if input_extension in LINEAR_IMAGE_FORMATS: input_linear = True else: input_linear = False if arguments.input_image is not None: assert os.path.exists(arguments.input_image), '"{0}" input image doesn\'t exists!'.format(arguments.input_image) image_path = arguments.input_image else: image_path = DEFAULT_IMAGE_PATH if is_openimageio_installed: image = read_image(str(image_path)) if not input_linear: colourspace = RGB_COLOURSPACES[arguments.input_oecf] image = colourspace.inverse_transfer_function(image) # Keeping RGB channels only. image = image[..., 0:3] image = image[:: int(arguments.input_resample), :: int(arguments.input_resample)] else: warning('"OpenImageIO" is not available, image reading is not supported, ' "falling back to some random noise!") image = None if not arguments.enable_warnings: warnings.filterwarnings("ignore") ColourAnalysis( image, arguments.input_image, arguments.input_colourspace, arguments.input_oecf, input_linear, arguments.reference_colourspace, arguments.correlate_colourspace, settings, arguments.layout, ) return run()
def test_light_probe_sampling_variance_minimization(self): """ Tests :func:`colour_hdri.sampling.variance_minimization.\ light_probe_sampling_variance_minimization` definition. """ image = read_image(str(os.path.join( SAMPLING_DIRECTORY, 'tests_light_probe_sampling_variance_minimization.exr'))) lights = light_probe_sampling_variance_minimization(image) uvs = np.array([light[0] for light in lights]) colours = np.array([light[1] for light in lights]) indexes = np.array([light[2] for light in lights]) np.testing.assert_almost_equal( uvs, np.array( [[0.16015625, 0.11328125], [0.15625000, 0.32421875], [0.42968750, 0.11328125], [0.42968750, 0.32031250], [0.16796875, 0.48437500], [0.43359375, 0.48437500], [0.18359375, 0.74218750], [0.44140625, 0.75390625], [0.64843750, 0.11718750], [0.64843750, 0.35156250], [0.87500000, 0.11718750], [0.87500000, 0.35937500], [0.64062500, 0.54687500], [0.87500000, 0.54687500], [0.64843750, 0.79687500], [0.87500000, 0.80078125]]), decimal=7) np.testing.assert_almost_equal( colours, np.array( [[40.65992016, 226.11660475, 266.78098774], [30.73776919, 130.37145448, 161.10773420], [98.10281688, 201.29676312, 299.40549910], [74.89445847, 117.00525796, 191.89859456], [42.24291545, 125.58142895, 167.82099468], [90.15780473, 102.82409275, 192.97436064], [82.17253280, 97.55175847, 179.72394174], [152.10083479, 72.06310755, 224.16233468], [128.44782221, 173.29928458, 301.74819988], [105.67531514, 104.05130512, 209.73328489], [196.73262107, 196.16986090, 392.89716852], [154.23001331, 111.56532115, 265.79564852], [120.04539376, 81.22123903, 201.26542896], [191.57947493, 95.21154106, 286.79548484], [168.29435712, 45.09299320, 213.38641733], [253.65272349, 50.30476046, 303.96245855]]), decimal=7) np.testing.assert_array_equal( indexes, np.array([[29, 41], [83, 40], [29, 110], [82, 110], [124, 43], [124, 111], [190, 47], [193, 113], [30, 166], [90, 166], [30, 224], [92, 224], [140, 164], [140, 224], [204, 166], [205, 224]]))