pm21-dragon/exercises/source/exercise-09/1__Image_analysis_1.ipynb

502 lines
472 KiB
Plaintext
Raw Normal View History

2024-12-12 11:17:35 -05:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# You must run this cell, but you can ignore its contents.\n",
"\n",
"import hashlib\n",
"\n",
"def ads_hash(ty):\n",
" \"\"\"Return a unique string for input\"\"\"\n",
" ty_str = str(ty).encode()\n",
" m = hashlib.sha256()\n",
" m.update(ty_str)\n",
" return m.hexdigest()[:10]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Numpy array for images"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"nbgrader": {
"grade": false,
"grade_id": "cell-6a738215de5622a5",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Images are saved in computers as arrays of numbers. In Python, the library called `numpy` (often abbreviated `np` for short). is the most common way to manipulate arrays of numbers. Here we will create an 8x8 pixel image and put it in the variable `check`."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0., 1., 0., 1., 0., 1., 0., 1.],\n",
" [1., 0., 1., 0., 1., 0., 1., 0.],\n",
" [0., 1., 0., 1., 0., 1., 0., 1.],\n",
" [1., 0., 1., 0., 1., 0., 1., 0.],\n",
" [0., 1., 0., 1., 0., 1., 0., 1.],\n",
" [1., 0., 1., 0., 1., 0., 1., 0.],\n",
" [0., 1., 0., 1., 0., 1., 0., 1.],\n",
" [1., 0., 1., 0., 1., 0., 1., 0.]])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a variable called `check` which will contain an 8x8 array of numbers.\n",
"check = np.zeros((8, 8))\n",
"check[::2, 1::2] = 1\n",
"check[1::2, ::2] = 1\n",
"check"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAGdCAYAAAAv9mXmAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAY+klEQVR4nO3df2zU9R3H8dcXag/F3ldBijQc0DAyQH6I1LECzinYpSFEtozpoqyMbUmTyg8bM4f+oVkWjmXZH1uczYpLN0JIzaIg6gBLJkXD2ApKxphBGMR2AmMQuW/pH0dsv/uLix1Q7nvt+/vttzwfySW72/fb7zuf6j393rft1/F93xcAAANsWNQDAACGJgIDADBBYAAAJggMAMAEgQEAmCAwAAATBAYAYILAAABMFIV9wJ6eHp0+fVolJSVyHCfswwMA+sH3fXV2dqqsrEzDhvV9jhJ6YE6fPq1UKhX2YQEAA6ijo0Pjx4/vc5vQA1NSUhL2IQdMJpOJeoSCuK4b9QgFY83DxXqHL25r7nmeUqlUXu/loQcmzh+LJZPJqEe46bDm4WK9wxfXNc/nvZyL/AAAEwQGAGCCwAAATBAYAIAJAgMAMEFgAAAmCAwAwASBAQCYIDAAABMEBgBggsAAAEwQGACACQIDADBBYAAAJggMAMAEgQEAmCgoMC+//LLKy8s1YsQIzZ07V++9995AzwUAiLnAgXn11Ve1bt06Pf/88/rwww/1wAMPqLq6Wu3t7RbzAQBiyvF93w+yw7x583TfffepoaEh99q0adO0bNkypdPpG+7veV5s758dcKkGjTjfppo1DxfrHb64rfmV9/BMJnPD2z0HOoO5fPmyDh06pKqqql6vV1VVaf/+/dfcJ5vNyvO8Xg8AwNAXKDDnz59Xd3e3xo4d2+v1sWPH6uzZs9fcJ51Oy3Xd3COVShU+LQAgNgq6yP//p6O+71/3FHX9+vXKZDK5R0dHRyGHBADETFGQje+66y4NHz78qrOVc+fOXXVWc0UikVAikSh8QgBALAU6gykuLtbcuXPV0tLS6/WWlhbNn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nwxXXNWe/wxXXNQ7kGAwDAtRAYAIAJAgMAMEFgAAAmCAwAwASBAQCYIDAAABMEBgBggsAAAEwQGACACQIDADBBYAAAJggMAMAEgQEAmCAwAAATBAYAYCLQHS0Hkuu6UR26YHG9qVFcb2gkseZhY73DF7c1v3LTyHxwBgMAMEFgAAAmCAwAwASBAQCYIDAAABMEBgBggsAAAEwQGACACQIDADBBYAAAJggMAMAEgQEAmCAwAAATBAYAYILAAABMEBgAgAkCAwAwQWAAACb6FZh0Oi3HcbRu3boBGgcAMFQUHJi2tjY1NjZq1qxZAzkPAGCIKCgwly5d0hNPPKFNmzbpzjvvHOiZAABDQEGBqaur05IlS7R48eKBngcAMEQUBd2hublZH3zwgdra2vLaPpvNKpvN5p57nhf0kACAGAp0BtPR0aG1a9dqy5YtGjFiRF77pNNpua6be6RSqYIGBQDEi+P7vp/vxtu3b9c3v/lNDR8+PPdad3e3HMfRsGHDlM1me/1/0rXPYOIamQBLNag4jhP1CAVjzcPFeocvbmvueZ5c11Umk1Eymexz20AfkS1atEhHjhzp9dr3v/99TZ06Vc8+++xVcZGkRCKhRCIR5DAAgCEgUGBKSko0Y8aMXq+NHDlSo0ePvup1AMDNjd/kBwCYCPxTZP9v7969AzAGAGCo4QwGAGCCwAAATBAYAIAJAgMAMEFgAAAmCAwAwASBAQCYIDAAABMEBgBggsAAAEwQGACACQIDADBBYAAAJggMAMAEgQEAmCAwAAAT/b7hWKEymYy
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Now lets view our 8x8 pixel image:\n",
"plt.imshow(check, cmap='gray');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Questions Part A - Image representation\n",
"\n",
"Use numpy slicing to set the values in an array:\n",
"\n",
"- Use `plt.imshow` to show a new 8x8 pixel image in which the top half is white and the bottom half is black.\n",
"- Use `plt.imshow` to show a new 8x8 pixel image in which the left half is white and the right half is black."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"nbgrader": {
"grade": true,
"grade_id": "cell-4ee9d19bc490e8bf",
"locked": false,
"points": 1,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAGdCAYAAAAv9mXmAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAXBElEQVR4nO3df2xV9f348deFykWxvQpapOGKhJmhIqjUOUDn/MXSEKNbxnRRh3P7g6QqrDFz6h+aZbMuy/7Y4mQrmk7DDGZRELMhQqZV45yAkjFmEKcRpjKmkV7kj0uE8/njmzXrFyi9pe9ebn08knfiPZ7DeYWY+/Scc2+by7IsCwAYZCOqPQAAw5PAAJCEwACQhMAAkITAAJCEwACQhMAAkITAAJBE3VCf8MCBA/HBBx9EfX195HK5oT49AEchy7LYs2dPNDU1xYgRfV+jDHlgPvjggygWi0N9WgAG0Y4dO2LixIl97jPkgamvr4+I/zdcQ0PDUJ8egKNQKpWiWCz2vJf3ZcgD89/bYg0NDQIDUKP684jDQ34AkhAYAJIQGACSEBgAkhAYAJIQGACSEBgAkhAYAJIQGACSEBgAkhAYAJIQGACSEBgAkhAYAJIQGACSEBgAkhhQYB566KGYPHlyjB49OmbOnBkvvfTSYM8FQI2rODBPPPFELF68OO65555444034pJLLomWlpbYvn17ivkAqFG5LMuySg646KKL4oILLoglS5b0bDvrrLPi2muvjfb29iMeXyqVolAoRHd3t1+ZDFBjKnkPr+gKZt++fbFx48aYO3dur+1z586NV1555ZDHlMvlKJVKvRYAw19Fgfnoo49i//79MX78+F7bx48fHzt37jzkMe3t7VEoFHpWsVgc+LQA1IwBPeTP5XK9XmdZdtC2/7rrrruiu7u7Z+3YsWMgpwSgxtRVsvMpp5wSI0eOPOhqZdeuXQdd1fxXPp+PfD4/8AkBqEk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wADAMDCkxra2vMmzcvrrzyysGeB4Bhoq7SA5YvXx6vv/56rF+/vl/7l8vlKJfLPa9LpVKlpwSgBlV0BbNjx45YtGhRLFu2LEaPHt2vY9rb26NQKPSsYrE4oEEBqC25LMuy/u68cuXK+PrXvx4jR47s2bZ///7I5XIxYsSIKJfLvf5dxKGvYEQGoLZ1d3dHQ0NDn/tUdIvsiiuuiM2bN/fa9t3vfjemTp0ad95550FxiYjI5/ORz+crOQ0Aw0BFgamvr49p06b12jZmzJgYN27cQdsB+HzzTX4AkqjoGcxgKJVKUSgUhvKUAAyy/jyDcQUDQBICA0ASAgNAEgIDQBICA0ASAgNAEgIDQBICA0ASAgNAEgIDQBICA0ASAgNAEgIDQBICA0ASAgNAEgIDQBICA0ASAgNAEgIDQBICA0ASAgNAEgIDQBICA0ASAgNAEgIDQBICA0ASAgNAEgIDQBICA0ASAgNAEgIDQBICA0ASAgNAEgIDQBICA0ASAgNAEhUF5r777otcLtdrnXbaaalmA6CG1VV6wDnnnBPr1q3reT1y5MhBHQiA4aHiwNTV1blqAeCIKn4Gs23btmhqaorJkyfH9ddfH++8806f+5fL5SiVSr0WAMNfRYG56KKL4rHHHos1a9bE0qVLY+fOnTF79uz4+OOPD3tMe3t7FAqFnlUsFo96aACOfbksy7KBHrx3796YMmVK/PCHP4y2trZD7lMul6NcLve8LpVKIgNQ47q7u6OhoaHPfSp+BvO/xowZE+eee25s27btsPvk8/nI5/NHcxoAatBRfQ+mXC7Hm2++GRMmTBiseQAYJioKzB133BFdXV3x7rvvxl//+tf45je/GaVSKRYsWJBqPgBqVEW3yP71r3/Ft7/97fj
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# The top half is white and the bottom half is black.\n",
"arr = np.zeros((8,8))\n",
"arr[:4,:] = 1\n",
"plt.imshow(arr, cmap='gray');"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"nbgrader": {
"grade": true,
"grade_id": "cell-9d1baa0ef55db4c6",
"locked": false,
"points": 1,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAGdCAYAAAAv9mXmAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAXYUlEQVR4nO3df2xV9f3H8deB2oti79UixTZcoGFkgKWI1LEWnFOwS0OIbBnTRVkZ25ImlR82Zg79Q7MsXJZlf2xxNms13QghNYtScRvUktmiYWwFbcaYwTKI7YSOQeTe0j9OY3u+f3zjzTqg3HPbd0/v5flITrJ7dk7Pe8bc58753Ns6nud5AgBgnE0JegAAQHYiMAAAEwQGAGCCwAAATBAYAIAJAgMAMEFgAAAmCAwAwETORF9weHhY586dU15enhzHmejLAwDGwPM89ff3q6ioSFOmjH6PMuGBOXfunKLR6ERfFgAwjnp7ezV79uxRj5nwwOTl5Un6/+HC4fBEXx6YEJFIJOgRAFOfv5ePZsID8/ljsXA4TGAAIEOlssTBIj8AwASBAQCYIDAAABMEBgBggsAAAEwQGACACQIDADBBYAAAJggMAMAEgQEAmCAwAAATBAYAYILAAABMEBgAgAkCAwAwQWAAACbSCszLL7+s4uJiTZs2TcuXL9e777473nMBADKc78C89tpr2r59u55//nl98MEHeuCBB1RVVaWenh6L+QAAGcrxPM/zc8KKFSt03333qb6+Prlv0aJFWr9+vWKx2A3PTyQSikQiisfj/MlkZK1U/pwskMlSeQ/3dQczODio48ePq7KycsT+yspKHTly5JrnuK6rRCIxYgMAZD9fgbl48aKGhoY0a9asEftnzZqlvr6+a54Ti8UUiUSSWzQaTX9aAEDGSGuR/39v/z3Pu+4jgR07digejye33t7edC4JAMgwOX4OvuuuuzR16tSr7lYuXLhw1V3N50KhkEKhUPoTAgAykq87mNzcXC1fvlxtbW0j9re1tamiomJcBwMAZDZfdzCSVFdXp40bN6qsrEzl5eVqaGhQT0+PampqLOYDAGQo34F57LHHdOnSJf34xz/W+fPnVVJSoj/+8Y+aO3euxXwAgAzl+3swY8X3YHAz4HswyHbj/j0YAABSRWAAACYIDADABIEBAJggMAAAEwQGAGCCwAAATBAYAIAJAgMAMEFgAAAmCAwAwASBAQCYIDAAABMEBgBggsAAAEwQGACACQIDADBBYAAAJggMAMAEgQEAmCAwAAATBAYAYILAAABMEBgAgAkCAwAwQWAAACYIDADABIEBAJggMAAAEwQGAGCCwAAATBAYAIAJAgMAMEFgAAAmCAwAwITvwBw+fFjr1q1TUVGRHMdRS0uLwVgAgEznOzADAwNaunSpXnrpJYt5AABZIsfvCVVVVaqqqrKYBQCQRXwHxi/XdeW6bvJ1IpGwviQAYBIwX+SPxWKKRCLJLRqNWl8SADAJmAdmx44disfjya23t9f6kgCAScD8EVkoFFIoFLK+DABgkuF7MAAAE77vYK5cuaLTp08nX589e1ZdXV3Kz8/XnDlzxnU4AEDmcjzP8/yc0N7eroceeuiq/dXV1frNb35zw/MTiYQikYji8bjC4bCfSwMZw3GcoEcATKXyHu77DuarX/2qfDYJAHATYg0GAGCCwAAATBAYAIAJAgMAMEFgAAAmCAwAwASBAQCYIDAAABMEBgBggsAAAEwQGACACQIDADBBYAAAJggMAMAEgQEAmCAwAAATBAYAYILAAABMEBgAgAkCAwAwQWAAACYIDADABIEBAJggMAAAEwQGAGCCwAAATBAYAIAJAgMAMEFgAAAmCAwAwASBAQCYIDAAABMEBgBggsAAAEwQGACACV+BicViuv/++5WXl6eCggKtX79ep06dspoNAJDBfAWmo6NDtbW1Onr0qNra2vTZZ5+psrJSAwMDVvMBADKU43mel+7J//nPf1RQUKCOjg595StfSemcRCKhSCSieDyucDic7qWBSc1xnKBHAEyl8h6eM9YLSFJ+fv51j3FdV67rJl8nEomxXBIAkCHSXuT3PE91dXVatWqVSkpKrntcLBZTJBJJbtFoNN1LAgAySNqPyGpra/WHP/xB7733nmbPnn3d4651BxONRnlE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OTjU0NKi0tHQ85wEAZIm0AnPlyhU98cQTamxs1J133jneMwEAskBagamtrdXatWu1Zs2a8Z4HAJAlcvye0NzcrPfff1+dnZ0pHe+6rlzXTb5OJBJ+LwkAyEC+7mB6e3u1bds27dmzR9OmTUvpnFgspkgkktyi0WhagwIAMovjeZ6X6sEtLS36+te/rqlTpyb3DQ0NyXEcTZkyRa7rjvjvpGvfwUSjUcXjcYXD4XH4nwBMPo7jBD0CYCqV93Bfj8hWr16tEydOjNj33e9+VwsXLtSzzz57VVwkKRQKKRQK+bkMACAL+ApMXl6eSkpKRuybPn26ZsyYcdV+AMDNjW/yAwBM+P4U2f9qb28fhzEAANmGOxgAgAkCAwAwQWAAACYIDADABIEBAJggMAAAEwQGAGCCwAAATBAYAIAJAgMAMEFgAAAmCAwAwASBAQCYIDAAABMEBgBggsAAAEwQGACACQIDADBBYAAAJggMAMAEgQEAmCAwAAATBAYAYILAAABMEBgAgAkCAwAwQWAAACYIDADABIEBAJggMAAAEwQGAGCCwAAATBAYAIAJAgMAMEFgAAAmCAwAwISvwLz44otyHGfEdvfdd1vNBgDIYDl+T7jnnnt06NCh5OupU6eO60AAgOzgOzA5OTnctQAAbsj3Gkx3d7eKiopUXFysxx9/XGfOnBn1eNd1lUgkRmwAgOznKzArVqzQ7t271draqsbGRvX19amiokKXLl267jmxWEyRSCS5RaPRMQ8NAJj8HM/zvHRPHhgY0Pz58/XDH/5QdXV
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# The left half is white and the right half is black.\n",
"arr = np.zeros((8,8))\n",
"arr[:,:4] = 1\n",
"plt.imshow(arr, cmap='gray');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Questions Part B - More image representation\n",
"\n",
"Write the numerical value corresponding with each pixel. In other words, what number corresponds with the black color and which number corresponds with the white color?"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"nbgrader": {
"grade": false,
"grade_id": "cell-2fd29ad721f075e0",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Type your answer here and then run this and the following cell.\n",
"black = 'replace this with your answer'\n",
"white = 'replace this with your answer'\n",
"\n",
"black = 0\n",
"white = 1"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"nbgrader": {
"grade": true,
"grade_id": "cell-4f11d45d5fbbe454",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"# If this runs without error, it means the answer in your previous cell was correct.\n",
"assert ads_hash(float(black))=='8aed642bf5'\n",
"assert ads_hash(float(white))=='d0ff5974b6'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Questions Part C - More image representation and contrast enhancement\n",
"\n",
"Now let's look at a more interesting image. We will use data included with the library `skimage` (also called scikit-image). The homepage for scikit-image is [here](http://scikit-image.org/)."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAGGCAYAAAB/gCblAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9aYykyXUeCj+5VtaSVVn70ntP96wcDWehSJPXtGgLBK91BS8QZAmwLQuwAa+ADfuf4E2GAcOW7GtL14AlU7Isy76+FmXJlChLIkFS9HDIWTQcdk/PdM/0Wl3dVdW1ZmZlZeX6/ajviX7y9Ik3s3pI3fujAyhUvu8by4mIE2ePiFS32+3iUXqUHqVH6VF6lP7/Kf3/NgCP0qP0KD1Kj9L/t9IjxvAoPUqP0qP0KPWkR4zhUXqUHqVH6VHqSY8Yw6P0KD1Kj9Kj1JMeMYZH6VF6lB6lR6knPWIMj9Kj9Cg9So9ST3rEGB6lR+lRepQepZ70iDE8So/So/QoPUo96RFjeJQepUfpUXq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WrZ913pidE99tx6jVHprmZjinUcrBkkDawxWIrZcz+PS3qBb4qkd5eBrGeuz8CZCB0F/q9Ti5bfwWMaRVMb22yuv76y07DEjj7l5C1G/ZbPZgebF64/nc7EM1ban7cT67yWdDysocIF6dQJ4QDOJpVgI76CmLkv8Y9pHjOAnmc4eVts4Srl+i38QrcLmGySPl+w8WEk6SbrV+Y4RTo8OWOKc9E3XmteGFQT539N0tL6YhkQNW8tofqVVHAObV+ekn5Du0ZejpIc6XVUBtsArYJ6jxhL9pPotwfYImYUxCYls6vfOajsWVu85iTh
"text/plain": [
"<Figure size 400x400 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# If import skimage fails, you can install it like this in Jupyter:\n",
"# !pip install scikit-image\n",
"# or like this at the command line:\n",
"# python -m pip install scikit-image\n",
"from skimage import data\n",
"\n",
"# Load the sample image data into a variable called `camera`.\n",
"camera = data.camera()\n",
"\n",
"plt.figure(figsize=(4, 4))\n",
"plt.imshow(camera, cmap='gray', interpolation='nearest', vmin=0, vmax=255)\n",
"plt.axis('off')\n",
"\n",
"plt.tight_layout()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So, let's checkout some things about the image. How many pixels are here? Put your answer in the `num_pixels` variable."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"nbgrader": {
"grade": false,
"grade_id": "cell-35aec8ec167eaa1a",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [],
"source": [
"# Type your answer here and then run this and the following cell.\n",
"num_pixels = camera.shape[0]*camera.shape[1]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"nbgrader": {
"grade": true,
"grade_id": "cell-9eda0f4283380a85",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"# If this runs without error, it means the answer in your previous cell was correct.\n",
"assert ads_hash(num_pixels)=='54faea9b3e'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What is the distribution of luminance values in the image?"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkQAAAGwCAYAAABIC3rIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA3iElEQVR4nO3de3RU9b3//9cASQhpGAiQm0ZATRFJoDXYEFBAbkKNEbEHJTZipaAHASPwRSi1BLUEOYdLSyoCIlCBol1HPK4DTQmIKISbkZRLKaXItSYGIUwChASS/fvDxf45hEt2yGRmsp+PtWYt5rM/s+c9HyaTVz77s/c4DMMwBAAAYGONvF0AAACAtxGIAACA7RGIAACA7RGIAACA7RGIAACA7RGIAACA7RGIAACA7TXxdgH+oqqqSl9//bVCQ0PlcDi8XQ4AAKgBwzBUWlqq6OhoNWp0/XkgAlENff3114qJifF2GQAAoBZOnDih22+//brbCUQ1FBoaKum7AW3evLmXqwEAADVRUlKimJgY8/f49RCIaujKYbLmzZsTiAAA8DM3W+7ComoAAGB7BCIAAGB7BCIAAGB7BCIAAGB7BCIAAGB7BCIAAGB7BCIAAGB7BCIAAGB7Xg1EGRkZcjgcbrfIyEhzu2EYysjIUHR0tIKDg9W7d2/t37/fbR/l5eUaO3asWrdurZCQEKWkpOjkyZNufYqLi5WWlian0ymn06m0tDSdPXu2Pl4iAADwA16fIerUqZMKCgrM2969e81ts2bN0pw5c5SVlaVdu3YpMjJS/fv3V2lpqdknPT1da9as0erVq7VlyxadO3dOycnJqqysNPukpqYqPz9f2dnZys7OVn5+vtLS0ur1dQIAAN/l9a/uaNKkidus0BWGYWjevHmaOnWqhgwZIklavny5IiIitGrVKj3//PNyuVxasmSJ3nvvPfXr10+StGLFCsXExGjDhg16+OGHdeDAAWVnZ2v79u1KTEyUJC1evFhJSUk6ePCgOnToUH8vFg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pU6eqzT59X1BQkJo3b+52AwAADZPXAlHfvn21d+9e5efnm7euXbvq6aefVn5+vu68805FRkYqJyfHfExFRYU2b96s7t27S5ISEhIUEBDg1qegoED79u0z+yQlJcnlcmnnzp1mnx07dsjlcpl9YE27yWvVbvJab5cBAECd8doaotDQUMXFxbm1hYSEqFWrVmZ7enq6ZsyYodjYWMXGxmrGjBlq1qyZUlNTJUlOp1MjRozQhAkT1KpVK4WFhWnixImKj483F2l37NhRAwcO1MiRI7Vw4UJJ0qhRo5ScnKwOHTrU4ysGAAC+yquLqm9m0qRJKisr0+jRo1VcXKzExEStX79eoaGhZp+5c+eqSZMmGjp0qMrKytS3b18tW7ZMjRs3NvusXLlS48aNM89GS0lJUVZWVr2/HgAA4JschmEY3i7CH5SUlMjpdMrlctl+PVFNDpcdnflIPVQCAPXvymcgn3P+oaa/v71+HSIAAABvIxABAADbIxABAGyNs2YhEYgAAAAIRAAAAAQiAABgewQiAABgewQiAABgewQiAABqgbPTGhYCEQAAsD0CEQAAsD0CEQAAsD0CEQAAsD0CEQAAsD0CEQAAsD0CEQAAsD3LgejEiRM6efKkeX/nzp1KT0/XokWL6rQwAACA+mI5EKWmpmrTpk2SpMLCQvXv3187d+7Ur371K7322mt1XiAAAICnWQ5E+/bt009+8hNJ0gcffKC4uDjl5uZq1apVWrZsWV3XBwBAnWg3eS1Xl8Z1WQ5Ely5dUlBQkCRpw4YNSklJkSTdc889KigoqNvqAAAA6oHlQNSpUye9/fbb+vzzz5WTk6OBAwdKkr7++mu1atWqzgs
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.hist(camera.flat,bins=256);\n",
"plt.xlabel('luminance');\n",
"plt.ylabel('number of occurances');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that there are two main peaks in the intensity histogram. We can also see that the intensities go from 0 to 255. This happens to be the range of values that fit in an 8 bit *byte*. This is the unit of memory size on modern computers. Is it correct to think that each pixel in this image is stored as a byte?\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dtype('uint8')"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"camera.dtype"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `dtype` of a numpy array is the \"data type\" - the type for each individual element of the array. Above we see the answer is `uint8` which means \"unsigned integer, 8 bits\". So, yes, each pixel is stored here as a byte."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you look at the histogram, you can see that there is some part of the luminance space which has very few occurances, namely above a luminance value of about 220. We can probably make better use of the 0-255 dynamic range available.\n",
"\n",
"In the cell below, enter a scale factor which fills the histogram of possible luminances more completely but does not cause too much clipping of the image values. The tower in the background should still be visible, for example. Look at the figures below to judge the effect of changing the scale factor. Put this in the variable `scale_factor`."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"nbgrader": {
"grade": false,
"grade_id": "cell-9ff4a4d60c8485d0",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"scale_factor = 255/220"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"nbgrader": {
"grade": true,
"grade_id": "cell-484ef1503b6e25a0",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"# assert that scale_factor is a number\n",
"assert scale_factor - 0.0 == scale_factor"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's look at the histogram of rescaled luminances."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkQAAAGwCAYAAABIC3rIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA7E0lEQVR4nO3de3RU5b3/8c8ASQg0DARIhmgE1IhoImrQELyAchFqjEp7UGIjthTkoGAEDkKpJfWSIKtcekiLgCgoULTriMdVbCQgoBBuRlIBKaUSbpoximESJCSQ7N8f/tzHIQGyw0wmk/1+rTVrOc9+Zs93P46Tj89+9h6HYRiGAAAAbKxFoAsAAAAINAIRAACwPQIRAACwPQIRAACwPQIRAACwPQIRAACwPQIRAACwvVaBLiBY1NTU6Msvv1RERIQcDkegywEAAPVgGIbKy8sVExOjFi3OPw9EIKqnL7/8UrGxsYEuAwAANMDRo0d1+eWXn3c7gaieIiIiJH0/oO3atQtwNQAAoD7KysoUGxtr/h0/HwJRPf1wmqxdu3YEIgAAgszFlruwqBoAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAAARMt6lr1G3qmkCXQSACAAAgEAEAANsjEAEAANsjEAEAANsjEAEAANsjEAEAANsjEAEAANsjEAEAANsjEAEAANsjEAEAANsLeCD64osv9Itf/EIdO3ZUmzZtdOONN6qgoMDcbhiGMjMzFRMTo/DwcPXv31979+712kdlZaXGjx+vTp06qW3btkpNTdWxY8e8+pSWlio9PV1Op1NOp1Pp6ek6ceJEYxwiAABo4gIaiEpLS3XbbbcpJCREf//73/XZZ59p9uzZat++vdln1qxZmjNnjnJycrRz5065XC4NGjRI5eXlZp+MjAytXr1aq1at0ubNm3Xy5EmlpKSourra7JOWlqbCwkLl5uYqNzdXhYWFSk9Pb8zDBQAATZURQM8884xx++23n3d7TU2N4XK5jJkzZ5ptp0+fNpxOp/Hyyy8bhmEYJ06cMEJCQoxVq1aZfb744gujRYsWRm5urmEYhvHZZ58Zkoxt27aZfbZu3WpIMv75z3/Wq1aPx2NIMjwej6VjBAAA59f1mb8ZXZ/5m9/2X9+/3wGdIXr33XfVu3dv/cd//IeioqJ00003afHixeb2oqIiud1uDR482GwLCwtTv379lJ+fL0kqKCjQmTNnvPrExMQoPj7e7LN161Y5nU4lJSWZffr06SOn02n2OVdlZaXKysq8HgAAoHkKaCA6ePCgFixYoLi4OL3//vsaO3asJkyYoNdff12S5Ha7JUnR0dFer4uOjja3ud1uhYaGqkOHDhfsExUVVev9o6KizD7nys7ONtcbOZ1OxcbGXtrBAgCAJiuggaimpkY333yzsrKydNNNN+nxxx/X6NGjtWDBAq9+DofD67lhGLXaznVun7r6X2g/06ZNk8fjMR9Hjx6t72EBAIAgE9BA1KVLF1133XVebT179tSRI0ckSS6XS5JqzeKUlJSYs0Yul0tVVVUqLS29YJ+vvvqq1vt//fXXtWaffhAWFqZ27dp5PQAAQPMU0EB02223af/+/V5t//rXv9S1a1dJUvfu3eVyuZSXl2dur6qq0qZNm9S3b19JUmJiokJCQrz6FBcXa8+ePWaf5ORkeTwe7dixw+yzfft2eTwesw8AALCvVoF886efflp9+/ZVVlaWhg8frh07dmjRokVatGiRpO9Pc2VkZCgrK0txcXGKi4tTVlaW2rRpo7S0NEmS0+nUqFGjNGnSJHXs2FGRkZGaPHmyEhISNHDgQEnfzzoNGTJEo0eP1sKFCyVJY8aMUUpKinr06BGYgwcAAE1GQAPRLbfcotWrV2vatGl67rnn1L17d82bN0+PPPKI2WfKlCmqqKjQuHHjVFpaqqSkJK1du1YRERFmn7lz56pVq1YaPny4KioqNGDAAC1dulQtW7Y0+6xYsUITJkwwr0ZLTU1VTk5O4x0sAABoshyGYRiBLiIYlJWVyel0yuPxsJ4IAAAf6TZ1jSTp0Mx7/bL/+v79DvhPdwAAAAQagQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANgegQgAANg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NGKSkpXGEGAAAkBTgQHTt2TCNGjNA333yjzp07q0+fPtq2bZu6du0qSZoyZYoqKio0btw4lZaWKikpSWvXrlVERIS5j7lz56pVq1YaPny4KioqNGDAAC1dulQtW7Y0+6xYsUITJkwwr0ZLTU1VTk5O4x4sAABoshyGYRiBLiIYlJWVyel0yuPxsJ7Igh/WDx2aeW+AKwEANEX+/jtR37/fTWoNEQAAQCAQiAAAgO0RiAAAgO0RiNAouBcRAKApIxABAADbIxABAADbIxABAADbIxABAADbIxABAADbIxABAADbIxABAABTt6lrbHmrFAIRAACwPQIRAACwPcuB6OjRozp27Jj5fMeOHcrIyNCiRYt8WhgAAEBjsRyI0tLStGHDBkmS2+3WoEGDtGPHDv3mN7/Rc8895/MCEZzseg4aABCcLAeiPXv26NZbb5UkvfXWW4qPj1d+fr5WrlyppUuX+ro+AAAAv7MciM6cOaO
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAGGCAYAAAB/gCblAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOy9aXCkWXUm/OSmTKUyU6ldKkm1dFV1dVV30xvQ0IAB29iY8XgJY5gYL+EYj7ewZwmHPQRehhl+eIIvbMOMGS/hGO/2gBc8YIbNpg1NQ+9rVXdV16qqUkmlPZWbcs/vh+Y5Onl075up6m6wiToRCknve9+7nnv2e26o3W63cRNuwk24CTfhJvw/CH+jO3ATbsJNuAk34Z8W3GQMN+Em3ISbcBM64CZjuAk34SbchJvQATcZw024CTfhJtyEDrjJGG7CTbgJN+EmdMBNxnATbsJNuAk3oQNuMoabcBNuwk24CR1wkzHchJtwE27CTeiAm4zhJtyEm3ATbkIHRHsteP36dfmbh6Xb7TZCoRBch6d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C5RI2+B39C9onwnKuqCtLPLS51TVOV6gtv3P9ALtPtPMZv9PjogbiYma+VCp6noI0dxfhZjsuxsb3lvC7/BS2z6697JvDIGFZ+25dwqpmspaJWWYcRFd90LPGoNMNcPNYbUF3ktKHiwjb1AV6oPYb3Y5rc/iII8u4NBjbHyuJuZDIfqPL2zZd/bCbzsWMXIzUZ/Jg2Vgs1oFgOlup7Z+VZrTE6fJZaGahTRH2GSFIK9DvNGPppY5vtLZhmUQvm6x
"text/plain": [
"<Figure size 400x400 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"rescaled = np.clip(scale_factor*camera.astype(np.float32),0,255).astype(np.uint8)\n",
"plt.hist(rescaled.flat,bins=256);\n",
"plt.xlabel('luminance');\n",
"plt.ylabel('number of occurances');\n",
"\n",
"plt.figure(figsize=(4, 4))\n",
"plt.imshow(rescaled, cmap='gray', interpolation='nearest', vmin=0, vmax=255)\n",
"plt.axis('off')\n",
"plt.tight_layout()\n",
"plt.show()"
]
}
],
"metadata": {
"celltoolbar": "Create Assignment",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}