Skip to content

Instantly share code, notes, and snippets.

@PavlosMelissinos
Last active May 5, 2017 14:12
Show Gist options
  • Save PavlosMelissinos/3c59567c0d8470daddeab607f2842d19 to your computer and use it in GitHub Desktop.
Save PavlosMelissinos/3c59567c0d8470daddeab607f2842d19 to your computer and use it in GitHub Desktop.
demonstration of CLAHE
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from ipywidgets import interact, fixed\n",
"from matplotlib import pyplot as plt\n",
"from utils import clahe\n",
"import ipywidgets as widgets\n",
"import cv2\n",
"\n",
"\n",
"def clahe_demo(img, clip_limit=3.0, tile_grid_size=8, figure_size=16):\n",
" result = clahe(img, mode='bgr', clip_limit=clip_limit, tile_grid_size=tile_grid_size)\n",
" \n",
" plt.figure(figsize=(figure_size, figure_size))\n",
" plt.subplot(1, 2, 1)\n",
" plt.imshow(img[:, :, ::-1])\n",
"\n",
" plt.subplot(1, 2, 2)\n",
" plt.imshow(result[:, :, ::-1])\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imfile = 'p1.jpg'\n",
"img = cv2.imread(imfile, 1)\n",
"res = interact(clahe_demo, img=fixed(img), mode=fixed('bgr'), \n",
" clip_limit=widgets.FloatSlider(min=0,max=30,step=0.1,value=3.0),\n",
" tile_grid_size=widgets.IntSlider(min=1,max=50,step=1,value=8),\n",
" figure_size=widgets.IntSlider(min=0,max=50,step=1,value=20))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imfile = 'p2.jpg'\n",
"img = cv2.imread(imfile, 1)\n",
"res = interact(clahe_demo, img=fixed(img), mode=fixed('bgr'), \n",
" clip_limit=widgets.FloatSlider(min=0,max=30,step=0.1,value=3.0),\n",
" tile_grid_size=widgets.IntSlider(min=1,max=50,step=1,value=8),\n",
" figure_size=widgets.IntSlider(min=0,max=50,step=1,value=20))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imfile = 'p3.jpg'\n",
"img = cv2.imread(imfile, 1)\n",
"res = interact(clahe_demo, img=fixed(img), mode=fixed('bgr'), \n",
" clip_limit=widgets.FloatSlider(min=0,max=30,step=0.1,value=3.0),\n",
" tile_grid_size=widgets.IntSlider(min=1,max=50,step=1,value=8),\n",
" figure_size=widgets.IntSlider(min=0,max=50,step=1,value=20))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment