-
Notifications
You must be signed in to change notification settings - Fork 0
/
commonfunctions.py
50 lines (40 loc) · 1.48 KB
/
commonfunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import skimage.io as io
import matplotlib.pyplot as plt
import numpy as np
from skimage.exposure import histogram
from matplotlib.pyplot import bar
from skimage.color import rgb2gray,rgb2hsv
# Convolution:
from scipy.signal import convolve2d
from scipy import fftpack
import math
from skimage.util import random_noise
from skimage.filters import median
from skimage.feature import canny
from skimage.measure import label
from skimage.color import label2rgb
# Edges
from skimage.filters import sobel_h, sobel, sobel_v,roberts, prewitt
# Show the figures / plots inside the notebook
def show_images(images,titles=None):
#This function is used to show image(s) with titles by sending an array of images and an array of associated titles.
# images[0] will be drawn with the title titles[0] if exists
# You aren't required to understand this function, use it as-is.
n_ims = len(images)
if titles is None: titles = ['(%d)' % i for i in range(1,n_ims + 1)]
fig = plt.figure()
n = 1
for image,title in zip(images,titles):
a = fig.add_subplot(1,n_ims,n)
if image.ndim == 2:
plt.gray()
plt.imshow(image)
a.set_title(title)
n += 1
fig.set_size_inches(np.array(fig.get_size_inches()) * n_ims)
plt.show()
def showHist(img):
# An "interface" to matplotlib.axes.Axes.hist() method
plt.figure()
imgHist = histogram(img, nbins=256)
bar(imgHist[1].astype(np.uint8), imgHist[0], width=0.8, align='center')