{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Copyright 2024 The mediapy Authors.\n", "#\n", "# Licensed under the Apache License, Version 2.0 (the \"License\");\n", "# you may not use this file except in compliance with the License.\n", "# You may obtain a copy of the License at\n", "#\n", "# http://www.apache.org/licenses/LICENSE-2.0\n", "#\n", "# Unless required by applicable law or agreed to in writing, software\n", "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", "# See the License for the specific language governing permissions and\n", "# limitations under the License." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# mediapy: Read/write/show images and videos in a Python notebook\n", "\n", "[**[GitHub source]**](https://github.com/google/mediapy) \n", "[**[API docs]**](https://google.github.io/mediapy/) \n", "[**[PyPI package]**](https://pypi.org/project/mediapy/) \n", "[**[Colab example]**](https://colab.research.google.com/github/google/mediapy/blob/main/mediapy_examples.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-02-18T07:44:06.659186Z", "iopub.status.busy": "2024-02-18T07:44:06.658892Z", "iopub.status.idle": "2024-02-18T07:44:08.172029Z", "shell.execute_reply": "2024-02-18T07:44:08.171454Z", "shell.execute_reply.started": "2024-02-18T07:44:06.659170Z" } }, "outputs": [], "source": [ "!command -v ffmpeg >/dev/null || (apt update && apt install -y ffmpeg)\n", "!pip install -q mediapy" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-02-18T07:44:08.173218Z", "iopub.status.busy": "2024-02-18T07:44:08.172732Z", "iopub.status.idle": "2024-02-18T07:44:08.429062Z", "shell.execute_reply": "2024-02-18T07:44:08.428465Z", "shell.execute_reply.started": "2024-02-18T07:44:08.173202Z" } }, "outputs": [], "source": [ "import itertools\n", "from typing import Any\n", "\n", "import matplotlib.pyplot as plt\n", "import mediapy as media\n", "import numpy as np\n", "\n", "# pylint: disable=missing-function-docstring, redefined-outer-name" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-02-18T07:44:08.430518Z", "iopub.status.busy": "2024-02-18T07:44:08.429826Z", "iopub.status.idle": "2024-02-18T07:44:08.433107Z", "shell.execute_reply": "2024-02-18T07:44:08.432591Z", "shell.execute_reply.started": "2024-02-18T07:44:08.430501Z" } }, "outputs": [], "source": [ "DATA_DIR = 'https://github.com/hhoppe/data/raw/main/' # Or any local path.\n", "IMAGE = DATA_DIR + 'image.png'\n", "VIDEO = DATA_DIR + 'video.mp4'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Image examples" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-02-18T07:44:08.434218Z", "iopub.status.busy": "2024-02-18T07:44:08.433973Z", "iopub.status.idle": "2024-02-18T07:44:08.448597Z", "shell.execute_reply": "2024-02-18T07:44:08.447997Z", "shell.execute_reply.started": "2024-02-18T07:44:08.434205Z" } }, "outputs": [ { "data": { "text/html": [ "
\n",
" \n",
" A title |
\n",
" \n",
" checkerboard | \n",
" \n",
" darker noise | \n",
" \n",
" as YCbCr | \n",
" \n",
" as YUV | \n",
" \n",
" rotated | \n",
" \n",
" thresholded |
\n",
" \n",
" gray | \n",
" \n",
" [0, 1] | \n",
" \n",
" bwr | \n",
" \n",
" jet | \n",
" \n",
" jet [0, 0.5] | \n",
" \n",
" radial |
\n",
" \n",
" 0 | \n",
" \n",
" 1 | \n",
" \n",
" 2 | \n",
" \n",
" 3 | \n",
" \n",
" 4 | \n",
" \n",
" 5 | \n",
" \n",
" 6 | \n",
" \n",
" 7 | \n",
" \n",
" 8 | \n",
" \n",
" 9 |
\n",
" \n",
" mirror loop | \n",
" \n",
" roll | \n",
" \n",
" fade |
\n",
" \n",
" seed=0 | \n",
" \n",
" seed=1 | \n",
" \n",
" seed=2 | \n",
" \n",
" seed=3 | \n",
" \n",
" seed=4 |
\n",
" \n",
" seed=5 | \n",
" \n",
" seed=6 | \n",
" \n",
" seed=7 | \n",
" \n",
" seed=8 | \n",
" \n",
" seed=9 |
| jpeg | \n",
" \n",
" quality=10 | \n",
" \n",
" quality=20 | \n",
" \n",
" quality=40 | \n",
" \n",
" quality=75 | \n",
" \n",
" quality=90 | \n",
" \n",
" quality=95 | \n",
" \n",
" quality=100 |