%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
SIZE = (20,10)
from skimage.io import imread
from skimage import color, feature, filter
fig = plt.figure(figsize=SIZE)
a=fig.add_subplot(2,1,1)
plt.axis('off')
img = imread("/home/carpedm20/data/food100/1/1.jpg")
plt.imshow(img)
a=fig.add_subplot(2,1,2)
plt.axis('off')
img_gray = imread("/home/carpedm20/data/food100/1/1.jpg", flatten=True)
plt.imshow(img_gray, cmap='gray')
plt.show()
fig, ax1 = plt.subplots(1, 1, figsize=SIZE)
arr, hog = feature.hog(img_gray, 8, (16,16), (1,1), True)
ax1.axis('off')
ax1.imshow(img_gray, cmap=plt.cm.gray)
ax1.imshow(hog)
plt.show()
for y in img:
for x in y:
x=1
print img[0][0]
fig, ax1 = plt.subplots(1, 1, figsize=SIZE)
ax1.imshow(img)
ax1.imshow(hog)
plt.show()
[16 19 12]
x = np.array([[1, 2, 3], [4, 5, 6]], np.int32)
type(x)
x.shape
x.dtype
a = np.array([1,2,4,8,6,5,1,2,1]).reshape(3,3)
print a
a.max()
print a[0][1]
print a[0]
a[:]+=1
print a
[[1 2 4] [8 6 5] [1 2 1]] 2 [1 2 4] [[2 3 5] [9 7 6] [2 3 2]]
img = imread("/home/carpedm20/data/food100/1/1.jpg")
type(img)
print img.shape
img_gray = imread("/home/carpedm20/data/food100/1/1.jpg", flatten=True)
print img_gray.shape
fig = plt.figure(figsize=SIZE)
plt.imshow(img)
print img[0][0]
new_img = img[::]-16
print new_img[0][0]
fig = plt.figure(figsize=SIZE)
plt.imshow(new_img)
(600, 800, 3) (600, 800) [16 19 12] [ 0 3 252]
<matplotlib.image.AxesImage at 0x7f84b4efa7d0>
img_gray = imread("/home/carpedm20/data/food100/1/1.jpg", flatten=True)
print img_gray.shape
size = (4,4)
plt.figure(1)
plt.imshow(img_gray[300:310,:10], cmap='gray', vmin=0, vmax=2, interpolation='nearest')
plt.colorbar()
print img_gray[300:305,:5]
new_img_gray = img_gray[:]+1
print new_img_gray[300:305,:5]
plt.figure(2)
plt.imshow(new_img_gray[300:310,:10], cmap='gray', vmin=0, vmax=2, interpolation='nearest')
plt.colorbar()
(600, 800) [[ 0.79928745 0.79453255 0.75952118 0.73655725 0.62534667] [ 0.78697216 0.77969451 0.75925333 0.71333333 0.54664745] [ 0.78195725 0.76905373 0.75871059 0.67297882 0.47157216] [ 0.78866157 0.77325804 0.72983804 0.62031686 0.41274863] [ 0.78224 0.76149333 0.71638392 0.56400824 0.36176824]] [[ 1.79928745 1.79453255 1.75952118 1.73655725 1.62534667] [ 1.78697216 1.77969451 1.75925333 1.71333333 1.54664745] [ 1.78195725 1.76905373 1.75871059 1.67297882 1.47157216] [ 1.78866157 1.77325804 1.72983804 1.62031686 1.41274863] [ 1.78224 1.76149333 1.71638392 1.56400824 1.36176824]]
<matplotlib.colorbar.Colorbar instance at 0x7f84b4cf46c8>
x = np.array([[1, 2, 3], [4, 5, 6]], np.int32)
fig = plt.figure(figsize=x.shape)
plt.imshow(x, cmap='gray')
print x.shape
plt.figure(1)
plt.imshow(x, cmap='gray', interpolation='nearest')
plt.grid(True)
print x
x[:]+=2
print x
fig = plt.figure(figsize=x.shape)
plt.figure(2)
plt.imshow(x, cmap='gray', interpolation='nearest')
plt.grid(True)
(2, 3) [[1 2 3] [4 5 6]] [[3 4 5] [6 7 8]]
img_gray = imread("/home/carpedm20/data/food100/1/1.jpg", flatten=True)
print img_gray.shape
plt.figure(1)
plt.imshow(img_gray, cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
print img_gray.max()
print img_gray[300:305,:5]
new_img_gray = img_gray[:]*1/5 # linear transformation
print new_img_gray[300:305,:5]
plt.figure(2)
plt.imshow(new_img_gray, cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
(600, 800) 1.0 [[ 0.79928745 0.79453255 0.75952118 0.73655725 0.62534667] [ 0.78697216 0.77969451 0.75925333 0.71333333 0.54664745] [ 0.78195725 0.76905373 0.75871059 0.67297882 0.47157216] [ 0.78866157 0.77325804 0.72983804 0.62031686 0.41274863] [ 0.78224 0.76149333 0.71638392 0.56400824 0.36176824]] [[ 0.15985749 0.15890651 0.15190424 0.14731145 0.12506933] [ 0.15739443 0.1559389 0.15185067 0.14266667 0.10932949] [ 0.15639145 0.15381075 0.15174212 0.13459576 0.09431443] [ 0.15773231 0.15465161 0.14596761 0.12406337 0.08254973] [ 0.156448 0.15229867 0.14327678 0.11280165 0.07235365]]
<matplotlib.colorbar.Colorbar instance at 0x7f84b4af0a28>
img_gray = imread("/home/carpedm20/data/food100/1/1.jpg", flatten=True)
print img_gray.shape
plt.figure(1)
plt.imshow(img_gray, cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
print img_gray.max()
print img_gray[300:305,:5]
new_img_gray = np.fliplr(img_gray) # linear transformation
print new_img_gray[300:305,:5]
plt.figure(2)
plt.imshow(new_img_gray, cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
(600, 800) 1.0 [[ 0.79928745 0.79453255 0.75952118 0.73655725 0.62534667] [ 0.78697216 0.77969451 0.75925333 0.71333333 0.54664745] [ 0.78195725 0.76905373 0.75871059 0.67297882 0.47157216] [ 0.78866157 0.77325804 0.72983804 0.62031686 0.41274863] [ 0.78224 0.76149333 0.71638392 0.56400824 0.36176824]] [[ 0.6847098 0.67462667 0.67098784 0.64548627 0.55863843] [ 0.6844498 0.6847098 0.64717569 0.61411373 0.56199451] [ 0.69788118 0.65866549 0.5978698 0.5958898 0.55415137] [ 0.69059569 0.61580314 0.54913647 0.52670039 0.49784275] [ 0.71750314 0.62674157 0.53121725 0.51382667 0.47936588]]
<matplotlib.colorbar.Colorbar instance at 0x7f84b49c6cf8>
from scipy import signal
img_gray = imread("/home/carpedm20/data/food100/1/1.jpg", flatten=True)
img_gray = img_gray[300:330,:30]
plt.figure(1)
plt.imshow(img_gray[2:-2,2:-2], cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
f = np.ones((3,3)) # linear filter : blur (with mean filter)
f = f/f.size
print f
new_img_gray = signal.convolve(img_gray, f)
plt.figure(2)
plt.imshow(new_img_gray[2:-2,2:-2], cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
[[ 0.11111111 0.11111111 0.11111111] [ 0.11111111 0.11111111 0.11111111] [ 0.11111111 0.11111111 0.11111111]]
<matplotlib.colorbar.Colorbar instance at 0x7f84b482f170>
from scipy import signal
img_gray = imread("/home/carpedm20/data/food100/1/1.jpg", flatten=True)
#img_gray = img_gray[300:330,:30]
img_gray = img_gray[200:300,:100]
plt.figure(1)
plt.imshow(img_gray[2:-2,2:-2], cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
f = np.ones((3,3)) # linear filter : blur (with mean filter)
f = f/f.size
ff = np.array([[0,0,0],
[0,2,0],
[0,0,0]])
f = ff-f # linear filter : Sharpening filter
new_img_gray = signal.convolve(img_gray, f)
plt.figure(2)
plt.imshow(new_img_gray[2:-2,2:-2], cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
<matplotlib.colorbar.Colorbar instance at 0x7f84b46f6908>
from skimage import filter
img_gray = imread("/home/carpedm20/data/food100/1/1.jpg", flatten=True)
#img_gray = img_gray[300:330,:30]
img_gray = img_gray[200:300,:100]
plt.figure(1)
plt.imshow(img_gray[2:-2,2:-2], cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
# Gaussian filter
# Removes "high-frequency" componets from the image (low-pass filter)
new_img_gray = filter.gaussian_filter(img_gray, sigma=1)
filter.gaussian_filter?
plt.figure(2)
plt.imshow(new_img_gray[2:-2,2:-2], cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
<matplotlib.colorbar.Colorbar instance at 0x7f84b45c8368>
from scipy import signal
img_gray = imread("/home/carpedm20/data/food100/1/1.jpg", flatten=True)
#img_gray = img_gray[300:330,:30]
img_gray = img_gray[200:300,:100]
plt.figure(1)
plt.imshow(img_gray[2:-2,2:-2], cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
f = np.ones((3,3)) # linear filter : blur (with mean filter)
f = f/f.size
ff = np.array([[0,0,0],
[0,2,0],
[0,0,0]])
blur = signal.convolve(img_gray, f)
detail = img_gray[1:-1,1:-1] - blur[2:-2,2:-2]
print detail[0][:5]
print detail.max()
plt.figure(2)
plt.imshow(detail[2:-2,2:-2], cmap='gray', vmin=0, vmax=detail.max(), interpolation='nearest')
plt.colorbar()
new_img_gray = img_gray[1:-1,1:-1] + detail*2
plt.figure(3)
plt.imshow(new_img_gray[2:-2,2:-2], cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
new_img_gray = img_gray[1:-1,1:-1] + detail*5
plt.figure(4)
plt.imshow(new_img_gray[2:-2,2:-2], cmap='gray', vmin=0, vmax=1, interpolation='nearest')
plt.colorbar()
[ 0.00521455 -0.00057473 0.0005258 -0.00248366 -0.0020488 ] 0.208732679739
<matplotlib.colorbar.Colorbar instance at 0x7f84b42707a0>
from skimage.morphology import disk
#print disk(5)
gradient = filter.rank.gradient(img_gray, disk(3))
print gradient.max()
plt.figure(1)
plt.imshow(gradient, cmap='gray', interpolation='nearest')
plt.colorbar()
f = np.array([[-1,0,1],
[-2,0,2],
[-1,0,1]])
new_img_gray = signal.convolve(img_gray, f)
plt.figure(2)
plt.imshow(new_img_gray, cmap='gray', interpolation='nearest')
plt.colorbar()
f = np.array([[1,2,1],
[0,0,0],
[-1,-2,-1]])
new_img_gray = signal.convolve(img_gray, f)
plt.figure(3)
plt.imshow(new_img_gray, cmap='gray', interpolation='nearest')
plt.colorbar()
238
/usr/local/lib/python2.7/dist-packages/skimage/util/dtype.py:107: UserWarning: Possible precision loss when converting from float64 to uint8 "%s to %s" % (dtypeobj_in, dtypeobj))
<matplotlib.colorbar.Colorbar instance at 0x7f84b450c7e8>
from skimage import data, color
img = color.rgb2gray(data.lena())
gradient = filter.rank.gradient(img, disk(3))
print gradient.max()
plt.figure(1)
plt.imshow(gradient, cmap='gray', interpolation='nearest')
plt.colorbar()
img = filter.gaussian_filter(img, sigma=1)
gradient = filter.rank.gradient(img, disk(3))
print gradient.max()
plt.figure(2)
plt.imshow(gradient, cmap='gray', interpolation='nearest')
plt.colorbar()
img = filter.gaussian_filter(img, sigma=3, mode='mirror')
#filter.gaussian_filter?
gradient = filter.rank.gradient(img, disk(3))
print gradient.max()
plt.figure(3)
plt.imshow(gradient, cmap='gray', interpolation='nearest')
plt.colorbar()
plt.figure(4)
plt.imshow(gradient, cmap='gray', interpolation='nearest')
plt.colorbar()
214 195 122
<matplotlib.colorbar.Colorbar instance at 0x7f84aff4b1b8>