a. Penggunaan mahotas.thresholding
[in] |
import numpy as np import mahotas import mahotas.demos from
mahotas.thresholding import soft_threshold from matplotlib import
pyplot as plt from os import path f =
mahotas.demos.load('luispedro', as_grey=True) f = f[:256,:256] plt.gray() # Show the data: print("Fraction
of zeros in original image: {0}".format(np.mean(f==0))) plt.imshow(f) plt.show() |
[out] |
|
b. Penggunaan mahotas.otsu
[in] |
import
mahotas import
mahotas.demos import
numpy as np from
pylab import imshow, gray, show from
os import path photo
= mahotas.demos.load('luispedro', as_grey=True) photo
= photo.astype(np.uint8) gray() imshow(photo) show() |
[out] |
|
[in] |
T_otsu =
mahotas.otsu(photo) print(T_otsu) imshow(photo > T_otsu) show() |
[out] |
|
[in] |
import mahotas import mahotas.demos import numpy as np from pylab import imshow,
gray, show from os import path photo =
mahotas.demos.load('luispedro', as_grey=True) photo =
photo.astype(np.uint8) T_otsu =
mahotas.otsu(photo) print(T_otsu) gray() imshow(photo > T_otsu) show() |
[out] |
|
[in] |
T_rc = mahotas.rc(photo) print(T_rc) imshow(photo > T_rc) show() |
[out] |
|
C. Segmentasi Chan Vase
[in] |
import matplotlib.pyplot as
plt from skimage import
data, img_as_float from
skimage.segmentation import chan_vese image = img_as_float(data.camera()) # Feel free to play
around with the parameters to see how they impact the result cv =
chan_vese(image, mu=0.25, lambda1=1, lambda2=1, tol=1e-3, max_iter=200, dt=0.5,
init_level_set="checkerboard", extended_output=True) fig, axes =
plt.subplots(2, 2, figsize=(8, 8)) ax = axes.flatten() ax[0].imshow(image,
cmap="gray") ax[0].set_axis_off() ax[0].set_title("Original
Image", fontsize=12) ax[1].imshow(cv[0],
cmap="gray") ax[1].set_axis_off() title =
"Chan-Vese segmentation - {} iterations".format(len(cv[2])) ax[1].set_title(title,
fontsize=12) ax[2].imshow(cv[1],
cmap="gray") ax[2].set_axis_off() ax[2].set_title("Final
Level Set", fontsize=12) ax[3].plot(cv[2]) ax[3].set_title("Evolution
of energy over iterations", fontsize=12) fig.tight_layout() plt.show() |
[out] |
|
[in] |
import
io import
zipfile import
requests import
numpy as np import
cv2 import matplotlib.pyplot
as plt %matplotlib
inline
img
= cv2.imread('keluarga.jpg')
gray
= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
path
= 'data/haarcascade_frontalface_default.xml' face_cascade
= cv2.CascadeClassifier(path)
for
x, y, w, h in face_cascade.detectMultiScale( gray, 1.3): cv2.rectangle( gray, (x, y), (x + w, y + h), (255,
0, 0), 2) fig,
ax = plt.subplots(1, 1, figsize=(8, 6)) ax.imshow(gray,
cmap=plt.cm.gray) ax.set_axis_off()
|
[out] |
|
Imam Farisi, 0006, Selesai
BalasHapus