From ef0abd57d4c18ac1b15af05540e02f255570a9a7 Mon Sep 17 00:00:00 2001 From: Adam French Date: Tue, 27 Jan 2026 11:28:15 +0000 Subject: [PATCH] plot image --- extract_data.ipynb | 76 ++++++++++++++++++++++++++++++++++++++++++++++ extract_data.py | 15 ++++++--- 2 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 extract_data.ipynb diff --git a/extract_data.ipynb b/extract_data.ipynb new file mode 100644 index 0000000..06d6fac --- /dev/null +++ b/extract_data.ipynb @@ -0,0 +1,76 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 7, + "id": "13389e33", + "metadata": {}, + "outputs": [], + "source": [ + "import extract_data as ed" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "e5de5ac0", + "metadata": {}, + "outputs": [], + "source": [ + "imgs = ed.get_images(ed.PHOTOS_PATH)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "575fd8c9", + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "module 'extract_data' has no attribute 'plot_image'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m img = ed.convert_to_opencv_image(imgs[\u001b[32m0\u001b[39m])\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[43med\u001b[49m\u001b[43m.\u001b[49m\u001b[43mplot_image\u001b[49m(img)\n", + "\u001b[31mAttributeError\u001b[39m: module 'extract_data' has no attribute 'plot_image'" + ] + } + ], + "source": [ + "img = ed.convert_to_opencv_image(imgs[0])\n", + "ed.plot_image(img)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8b7bebc", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.13.11" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/extract_data.py b/extract_data.py index e227031..a186b82 100644 --- a/extract_data.py +++ b/extract_data.py @@ -1,6 +1,8 @@ import os from datetime import datetime +import matplotlib.pyplot as plt + import cv2 as cv import numpy as np import pandas as pd @@ -9,7 +11,6 @@ from PIL import Image PHOTOS_PATH = "./photos/" - # Get a list of images given a directory path def get_images(url: str): images = [] @@ -126,6 +127,13 @@ def preview_image(img: np.ndarray): cv.waitKey(0) cv.destroyAllWindows() +def plot_image(img, figsize=(6,6)): + fig, ax = plt.subplots(figsize=figsize) + ax.imshow(img) + ax.axis("off") + + return fig + def __main__(): imgs = get_images(PHOTOS_PATH) @@ -157,7 +165,4 @@ def __main__(): print("success_len: ", len(success)) print("fail_len: ", len(fail)) - return None - - -__main__() + return None \ No newline at end of file