Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 12, 2024
1 parent 8242671 commit bc9d86d
Show file tree
Hide file tree
Showing 2 changed files with 292 additions and 263 deletions.
476 changes: 246 additions & 230 deletions colour_checker_detection/examples/examples_detection_inference.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"\n",
"from colour_checker_detection import (\n",
" ROOT_RESOURCES_EXAMPLES,\n",
" detect_colour_checkers_segmentation)\n",
" detect_colour_checkers_segmentation,\n",
")\n",
"\n",
"colour.plotting.colour_style()\n",
"\n",
Expand Down Expand Up @@ -114,15 +115,16 @@
],
"source": [
"COLOUR_CHECKER_IMAGE_PATHS = glob.glob(\n",
" os.path.join(ROOT_RESOURCES_EXAMPLES, 'detection', '*19*.png'))\n",
" os.path.join(ROOT_RESOURCES_EXAMPLES, \"detection\", \"*19*.png\")\n",
")\n",
"\n",
"COLOUR_CHECKER_IMAGES = [\n",
" colour.cctf_decoding(colour.io.read_image(path))\n",
" for path in COLOUR_CHECKER_IMAGE_PATHS\n",
"]\n",
"\n",
"for image in COLOUR_CHECKER_IMAGES:\n",
" colour.plotting.plot_image(colour.cctf_encoding(image));"
" colour.plotting.plot_image(colour.cctf_encoding(image))"
]
},
{
Expand Down Expand Up @@ -166,20 +168,19 @@
"SWATCHES = []\n",
"for image in COLOUR_CHECKER_IMAGES:\n",
" for colour_checker_data in detect_colour_checkers_segmentation(\n",
" image, additional_data=True):\n",
" \n",
" swatch_colours, swatch_masks, colour_checker_image = (\n",
" colour_checker_data.values)\n",
" image, additional_data=True\n",
" ):\n",
" swatch_colours, swatch_masks, colour_checker_image = colour_checker_data.values\n",
" SWATCHES.append(swatch_colours)\n",
" \n",
"\n",
" # Using the additional data to plot the colour checker and masks.\n",
" masks_i = np.zeros(colour_checker_image.shape)\n",
" for i, mask in enumerate(swatch_masks):\n",
" masks_i[mask[0]:mask[1], mask[2]:mask[3], ...] = 1\n",
" \n",
" masks_i[mask[0] : mask[1], mask[2] : mask[3], ...] = 1\n",
"\n",
" colour.plotting.plot_image(\n",
" colour.cctf_encoding(\n",
" np.clip(colour_checker_image + masks_i * 0.25, 0, 1)));"
" colour.cctf_encoding(np.clip(colour_checker_image + masks_i * 0.25, 0, 1))\n",
" )"
]
},
{
Expand Down Expand Up @@ -260,9 +261,10 @@
}
],
"source": [
"D65 = colour.CCS_ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']\n",
"D65 = colour.CCS_ILLUMINANTS[\"CIE 1931 2 Degree Standard Observer\"][\"D65\"]\n",
"REFERENCE_COLOUR_CHECKER = colour.CCS_COLOURCHECKERS[\n",
" 'ColorChecker24 - After November 2014']\n",
" \"ColorChecker24 - After November 2014\"\n",
"]\n",
"\n",
"colour_checker_rows = REFERENCE_COLOUR_CHECKER.rows\n",
"colour_checker_columns = REFERENCE_COLOUR_CHECKER.columns\n",
Expand All @@ -272,35 +274,47 @@
"# See https://github.com/colour-science/colour-checker-detection/discussions/59\n",
"# for more information.\n",
"REFERENCE_SWATCHES = colour.XYZ_to_RGB(\n",
" colour.xyY_to_XYZ(list(REFERENCE_COLOUR_CHECKER.data.values())),\n",
" 'sRGB', REFERENCE_COLOUR_CHECKER.illuminant)\n",
" colour.xyY_to_XYZ(list(REFERENCE_COLOUR_CHECKER.data.values())),\n",
" \"sRGB\",\n",
" REFERENCE_COLOUR_CHECKER.illuminant,\n",
")\n",
"\n",
"for i, swatches in enumerate(SWATCHES):\n",
" swatches_xyY = colour.XYZ_to_xyY(colour.RGB_to_XYZ(\n",
" swatches, 'sRGB', D65))\n",
" swatches_xyY = colour.XYZ_to_xyY(colour.RGB_to_XYZ(swatches, \"sRGB\", D65))\n",
"\n",
" colour_checker = colour.characterisation.ColourChecker(\n",
" os.path.basename(COLOUR_CHECKER_IMAGE_PATHS[i]),\n",
" dict(zip(REFERENCE_COLOUR_CHECKER.data.keys(), swatches_xyY)),\n",
" D65, colour_checker_rows, colour_checker_columns)\n",
" \n",
" D65,\n",
" colour_checker_rows,\n",
" colour_checker_columns,\n",
" )\n",
"\n",
" colour.plotting.plot_multi_colour_checkers(\n",
" [REFERENCE_COLOUR_CHECKER, colour_checker])\n",
" \n",
" [REFERENCE_COLOUR_CHECKER, colour_checker]\n",
" )\n",
"\n",
" swatches_f = colour.colour_correction(swatches, swatches, REFERENCE_SWATCHES)\n",
" swatches_f_xyY = colour.XYZ_to_xyY(colour.RGB_to_XYZ(\n",
" swatches_f, 'sRGB', D65))\n",
" swatches_f_xyY = colour.XYZ_to_xyY(colour.RGB_to_XYZ(swatches_f, \"sRGB\", D65))\n",
" colour_checker = colour.characterisation.ColourChecker(\n",
" '{0} - CC'.format(os.path.basename(COLOUR_CHECKER_IMAGE_PATHS[i])),\n",
" \"{0} - CC\".format(os.path.basename(COLOUR_CHECKER_IMAGE_PATHS[i])),\n",
" dict(zip(REFERENCE_COLOUR_CHECKER.data.keys(), swatches_f_xyY)),\n",
" D65, colour_checker_rows, colour_checker_columns)\n",
" \n",
" D65,\n",
" colour_checker_rows,\n",
" colour_checker_columns,\n",
" )\n",
"\n",
" colour.plotting.plot_multi_colour_checkers(\n",
" [REFERENCE_COLOUR_CHECKER, colour_checker])\n",
" [REFERENCE_COLOUR_CHECKER, colour_checker]\n",
" )\n",
"\n",
" colour.plotting.plot_image(colour.cctf_encoding(\n",
" colour.colour_correction(\n",
" COLOUR_CHECKER_IMAGES[i], swatches, REFERENCE_SWATCHES)));"
" colour.plotting.plot_image(\n",
" colour.cctf_encoding(\n",
" colour.colour_correction(\n",
" COLOUR_CHECKER_IMAGES[i], swatches, REFERENCE_SWATCHES\n",
" )\n",
" )\n",
" )"
]
},
{
Expand Down Expand Up @@ -414,8 +428,7 @@
],
"source": [
"for image in COLOUR_CHECKER_IMAGES:\n",
" for colour_checker_data in detect_colour_checkers_segmentation(\n",
" image, show=True):\n",
" for colour_checker_data in detect_colour_checkers_segmentation(image, show=True):\n",
" pass"
]
},
Expand Down

0 comments on commit bc9d86d

Please sign in to comment.