{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Add image metrics to a Table\n", "\n", "In this example we will extend a Table containing images with new columns containing common image metrics (sharpness, contrast, etc.).\n", "\n", "\n", "\n", "![img](../images/add-image-metrics.jpg)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install 3lc\n", "%pip install git+https://github.com/3lc-ai/3lc-examples.git" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import tlc\n", "\n", "from tlc_tools.add_columns_to_table import add_image_metrics_to_table" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Project setup\n", "\n", "We load the previously written COCO128 table from [create-table-from-coco-detection.ipynb](../1-create-tables/object%20detection/create-table-from-coco-detection.ipynb)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table = tlc.Table.from_names(\"initial\", \"COCO128\", \"3LC Tutorials - COCO128\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Extend the Table with image metrics" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "extended_table = add_image_metrics_to_table(\n", " table,\n", " image_metrics=[\"contrast\", \"sharpness\", \"brightness\", \"average_blue\", \"average_green\", \"average_red\"],\n", ")\n", "\n", "print(extended_table[0].keys()) # Notice only the \"image\" column is present in the \"sample-view\" of the table\n", "print(extended_table.table_rows[0].keys()) # Notice all the columns are present in the \"row-view\" of the table" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "extended_table" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3" } }, "nbformat": 4, "nbformat_minor": 2 }