{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "A notebook to test calculating of SNR, SSIM, and MSE for a filter using a number of randomly generated additive noise problems" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Setup\n", "Here we import the libraries we need" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt # plotting and showing images\n", "import numpy as np # handling arrays\n", "from skimage.io import imread # reading images\n", "#from skimage.measure import compare_ssim as ssim \n", "from skimage.metrics import structural_similarity as ssim # structural similarity\n", "mse = lambda img1, img2: np.sum(np.power(img1-img2,2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load and Show Phantom" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d=np.mean(imread('data/testpattern.png'),2)\n", "plt.imshow(d, cmap= 'gray')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Tasks\n", "Evaluate a number of different filters using different noise levels and determine which works the best under which circumstances. The example is done for a uniform filter, and you job is to add \n", "\n", " 1. gaussian\n", " 2. median \n", " 3. anisotropic diffusion (copy code from exercise 3) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Filter evaluation using uniform filter" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "scales = [0.1, 0.5, 1, 10, 20, 100];\n", "\n", "Ntests = 10;\n", "\n", "# initialize arrays for results\n", "mse1 = np.zeros((len(scales), Ntests), dtype = np.float32)\n", "ssim1 = np.zeros((len(scales), Ntests), dtype = np.float32)\n", "from scipy.ndimage.filters import uniform_filter\n", "current_filter = lambda img: uniform_filter(img, 5)\n", "\n", "for i, c_scale in enumerate(scales):\n", " for j in range(Ntests):\n", " x = current_filter(d+c_scale*np.random.uniform(-c_scale, c_scale, size = d.shape))\n", " mse1[i,j]=mse(d,x);\n", " ssim1[i,j]=ssim(d,x); \n", " # Add some lines here to display the latest image in a subplot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, (ax1, ax2) = plt.subplots(1,2)\n", "ax1.loglog(scales,np.mean(mse1,1)) # Add annotations for the plot and axes\n", "ax1.set_title('MSE vs Scale')\n", "ax1.set_xlabel('Scale')\n", "ax1.set_ylabel('MSE')\n", "\n", "ax2.semilogx(scales,np.mean(ssim1,1))\n", "ax2.set_title('SSIM vs Scale')\n", "ax2.set_xlabel('Scale')\n", "ax2.set_ylabel('SSIM')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# make a version of the plot showing SNR instead of scale" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Test run for Gauss filter\n", "\n", "### repeat the code from filter 1 \n", "\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Test run for Median filter\n", "\n", "### repeat the code from filter 1 \n", "\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Test run for Diffusion filter\n", "\n", "### repeat the code from filter 1 \n", "\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Summarize all results" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "hide_input": false, "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.7.3" } }, "nbformat": 4, "nbformat_minor": 1 }