Created
December 31, 2019 06:36
-
-
Save Akshat-mehrotra/1cbcb2cb28699d1078d1881121b4ca3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Benchmarking with skimage\n", | |
"We'll run every test 10 times. \n", | |
"Then take the mean of the 10 values to get the most accurate value" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import timeit\n", | |
"import numpy as np\n", | |
"\n", | |
"setup='''\n", | |
"from skimage import img_as_float\n", | |
"from skimage.morphology import disk\n", | |
"from skimage.io import imread, imsave\n", | |
"from skimage.filters.rank import tophat, mean, minimum, entropy\n", | |
"from skimage.feature import canny, corner_harris\n", | |
"from skimage.filters import gaussian\n", | |
"from skimage.transform import resize, integral_image\n", | |
"from skimage.transform.pyramids import pyramid_gaussian\n", | |
"from skimage.segmentation import clear_border\n", | |
"\n", | |
"img = imread(\"G:\\\\Book-Cover-Test\\\\img1.png\", as_gray = True)\n", | |
"'''\n", | |
"k='''\n", | |
"import numpy as np\n", | |
"k = np.zeros((500,385))\n", | |
"k[125:125+250, 96:96+192] = 1\n", | |
"'''\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Reading" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.0024" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = 'imread(\"G:\\\\Book-Cover-Test\\\\img1.png\")'\n", | |
"\n", | |
"time_reading=timeit.Timer(\n", | |
" setup=setup,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"np.round(np.mean(time_reading), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Saving" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.0478" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"\n", | |
"CODE = 'imsave(\"G:\\\\Book-Cover-Test\\\\img1.png\", img)'\n", | |
"\n", | |
"time_saving = timeit.Timer(\n", | |
" setup=setup,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_saving), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Canny Edge Detection" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.0466" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = \"canny(img,sigma=2.3)\"\n", | |
"time_canny = timeit.Timer(\n", | |
" setup=setup,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_canny), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Resize" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.0919" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = \"resize(img,(10,10))\"\n", | |
"\n", | |
"time_resize = timeit.Timer(\n", | |
" setup=setup,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_resize), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Integral of Image" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.0008" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = \"integral_image(img)\"\n", | |
"\n", | |
"time_integral = timeit.Timer(\n", | |
" setup=setup,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_integral), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Harris Corner Detection" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.0232" | |
] | |
}, | |
"execution_count": 30, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = \"corner_harris(img)\"\n", | |
"\n", | |
"time_harris = timeit.Timer(\n", | |
" setup=setup,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_harris), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test TopHat Filtering" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.0213" | |
] | |
}, | |
"execution_count": 16, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = \"tophat(img, disk(5))\"\n", | |
"time_tophat = timeit.Timer(\n", | |
" setup=setup,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_tophat), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Gaussian Blur" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.0072" | |
] | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = \"gaussian(img, sigma=4)\"\n", | |
"\n", | |
"time_blur = timeit.Timer(\n", | |
" setup=setup,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_blur), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Image Mean" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.3097" | |
] | |
}, | |
"execution_count": 21, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"\n", | |
"CODE = \"mean(img, k)\"\n", | |
"\n", | |
"time_mean = timeit.Timer(\n", | |
" setup=setup+k,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_mean), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Image Minimum" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 22, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.2957" | |
] | |
}, | |
"execution_count": 22, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = \"minimum(img, k)\"\n", | |
"\n", | |
"tie_min = timeit.Timer(\n", | |
" setup=setup+k,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(tie_min), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Image Changing Image To Float" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.001" | |
] | |
}, | |
"execution_count": 29, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = \"img_as_float(img)\"\n", | |
"\n", | |
"time_tofloat = timeit.Timer(\n", | |
" setup=setup,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_tofloat), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Image Entropy" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.7098" | |
] | |
}, | |
"execution_count": 25, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = \"entropy(img,k)\"\n", | |
"time_entropy = timeit.Timer(\n", | |
" setup=setup+k,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_entropy), 4)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test Gaussian Pyramid" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 27, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2e-06" | |
] | |
}, | |
"execution_count": 27, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CODE = \"pyramid_gaussian(img, 12, 1.5)\"\n", | |
"time_pyramid = timeit.Timer(\n", | |
" setup=setup,\n", | |
" stmt=CODE,\n", | |
").repeat(10, 1)\n", | |
"\n", | |
"np.round(np.mean(time_pyramid), 7)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"@webio": { | |
"lastCommId": null, | |
"lastKernelId": null | |
}, | |
"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.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment