added 4 assignment
This commit is contained in:
211
assignments/04_assignment.ipynb
Normal file
211
assignments/04_assignment.ipynb
Normal file
@@ -0,0 +1,211 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"source": [
|
||||
"# Image Processing SS 18 - Assignment - 04\n",
|
||||
"\n",
|
||||
"### Deadline is 16.5.2016 at 8:00 o'clock\n",
|
||||
"\n",
|
||||
"Please solve the assignments together with a partner.\n",
|
||||
"I will run every notebook. Make sure the code runs through. Select `Kernel` -> `Restart & Run All` to test it.\n",
|
||||
"Please strip the output from the cells, either select `Cell` -> `All Output` -> `Clear` or use the `nb_strip_output.py` script / git hook."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# display the plots inside the notebook\n",
|
||||
"%matplotlib inline"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import pylab\n",
|
||||
"try:\n",
|
||||
" import urllib.request as urllib2\n",
|
||||
"except ImportError:\n",
|
||||
" import urllib2\n",
|
||||
"\n",
|
||||
"import random\n",
|
||||
"try:\n",
|
||||
" from StringIO import StringIO as BytesIO\n",
|
||||
"except ImportError:\n",
|
||||
" from io import BytesIO\n",
|
||||
" \n",
|
||||
"from PIL import Image\n",
|
||||
"\n",
|
||||
"pylab.rcParams['figure.figsize'] = (12, 12) # This makes the plot bigger"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Exercise 1 - Qualify sharpness and noise - 5 Points\n",
|
||||
"\n",
|
||||
"Qualify the noise and sharpness in the images. Make a plot images, noise\n",
|
||||
"\n",
|
||||
"Please download sample picture from [here](http://www.imageprocessingplace.com/downloads_V3/root_downloads/image_databases/standard_test_images.zip)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Load the pictures here\n",
|
||||
"sample_images = None"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def qualify_noise(img):\n",
|
||||
" \"\"\"Qualify the noise based on the std of a gaussian model.\n",
|
||||
" You may find a window that is contant in the images.\n",
|
||||
" \"\"\"\n",
|
||||
" # your code here\n",
|
||||
" return random.randint(0, 10)\n",
|
||||
"\n",
|
||||
"plt.bar(range(len(sample_images)), [qualify_noise(i) for i in sample_images])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def qualify_sharpness(img):\n",
|
||||
" \"\"\"Qualify the sharpness based on the average pixel differences.\"\"\"\n",
|
||||
" # your code here\n",
|
||||
" return random.randint(0, 10)\n",
|
||||
"plt.bar(range(len(sample_images)), [qualify_sharpness(i) for i in sample_images])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Does the result match the expectations? If not what processing step can be done?/"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Exercise 2 - SSIM JPEG Compression - 5 Points"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def jpeg_enocde(img, quality):\n",
|
||||
" pil_img = Image.fromarray(img)\n",
|
||||
" buffer = BytesIO()\n",
|
||||
" im1.save(buffer, \"JPEG\", quality=quality)\n",
|
||||
" return buffer\n",
|
||||
"\n",
|
||||
"def jpeg_decode(buffer):\n",
|
||||
" img = Image.open(buffer)\n",
|
||||
" return np.array(img)\n",
|
||||
"\n",
|
||||
"def jpeg_quality_filter(img, quality):\n",
|
||||
" as_jpeg = jpeg_enocde(img, quality)\n",
|
||||
" return jpeg_decode(as_jpeg)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"len(images_for_jpeg)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"images10 = [jpeg_quality_filter(img, 10) for img in sample_images]\n",
|
||||
"images50 = [jpeg_quality_filter(img, 10) for img in sample_images]\n",
|
||||
"images80 = [jpeg_quality_filter(img, 10) for img in sample_images]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def ssim(img, filtered_img):\n",
|
||||
" \"\"\"The SSIM similarity measure. Use the parameters from the paper \n",
|
||||
" as on the second to last slide from the lecture\"\"\"\n",
|
||||
" # your code\n",
|
||||
" return random.randint(0, 10)\n",
|
||||
"\n",
|
||||
"for i, img in enumerate(images_for_jpeg):\n",
|
||||
" print(i)\n",
|
||||
" compressed_images = [images10[i], images50[i], images80[i]]\n",
|
||||
" plt.bar(range(len(compressed_images)),\n",
|
||||
" [ssim(img, comp) for comp in compressed_images])\n",
|
||||
" plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"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.5.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
Reference in New Issue
Block a user