Created
March 4, 2017 09:51
-
-
Save yuyyuyu/9cb09278a07a21832144d6eabb8ac5ae 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
import numpy as np | |
import matplotlib.pyplot as plt | |
import scipy.ndimage as ndimage | |
import skimage.filter as skif | |
from PIL import Image | |
import numpy as np | |
from matplotlib import pylab as plt | |
#open image and convert fromRGB to mono_color | |
img =Image.open('sudoku.jpg') | |
img=img.convert('L') | |
img=np.array(img) | |
# Defining minimum neighboring size of objects | |
block_size = 111 | |
# Adaptive threshold function which returns image | |
# map of structures that are different relative to | |
# background | |
adaptive_cut = skif.threshold_adaptive(img, block_size, offset=0) | |
# Global threshold('normal Binarization) | |
global_thresh = skif.threshold_otsu(img) | |
global_cut = img > global_thresh | |
# Creating figure to highlight difference between | |
# adaptive and global threshold methods | |
fig = plt.figure(figsize=(8, 4)) | |
fig.subplots_adjust(hspace=0.05, wspace=0.05) | |
ax1 = fig.add_subplot(131) | |
ax1.imshow(img,cmap='gray') | |
ax1.xaxis.set_visible(False) | |
ax1.yaxis.set_visible(False) | |
ax1 = fig.add_subplot(132) | |
ax1.imshow(global_cut,cmap='gray') | |
ax1.xaxis.set_visible(False) | |
ax1.yaxis.set_visible(False) | |
ax1 = fig.add_subplot(133) | |
ax1.imshow(adaptive_cut,cmap='gray') | |
ax1.xaxis.set_visible(False) | |
ax1.yaxis.set_visible(False) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment