Skip to content

Commit

Permalink
Minor changes, remove output and solutions, add PDF.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marie-Sophie von Braun authored and Marie-Sophie von Braun committed May 8, 2024
1 parent b51b09e commit 7790f25
Show file tree
Hide file tree
Showing 7 changed files with 620 additions and 946 deletions.
116 changes: 96 additions & 20 deletions day1.3_image_processing_basics/00_images_as_arrays.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"# Images are arrays of numbers\n",
"\n",
Expand All @@ -15,7 +19,11 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"import numpy as np\n",
Expand All @@ -24,7 +32,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"## Numpy arrays\n",
"\n",
Expand All @@ -34,7 +46,11 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -69,7 +85,11 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -98,15 +118,23 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"This output is almost the same as above with the difference that now it is indicated that we are dealing with a Numpy ```array```. Such Numpy arrays can now be treated as a one entity and we can perform the computation that we coudn't before:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"image = np.asarray(raw_image_array)"
Expand All @@ -115,7 +143,11 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
Expand All @@ -140,14 +172,22 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"Note that these computations are very efficient because they are *vectorized*, i.e. they can in principle be performed in parallel."
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"## Two important properties\n",
"\n",
Expand All @@ -159,7 +199,11 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
Expand All @@ -179,7 +223,11 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
Expand All @@ -198,7 +246,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"## Other ways of creating arrays\n",
"\n",
Expand All @@ -208,7 +260,11 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -236,7 +292,11 @@
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -265,15 +325,23 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"As images are just arrays, we just set pixel values as if we were accessing arrays. From this you also learn that the first axis (coordinate 0) is going from top to bottom while the second axis (coordinate 3) goes from left to right."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -304,15 +372,23 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"For studying noise, we can for example create an image with random values using [```np.random.random```](https://numpy.org/doc/stable/reference/random/generated/numpy.random.Generator.random.html#numpy.random.Generator.random)."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -362,4 +438,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
Loading

0 comments on commit 7790f25

Please sign in to comment.