Skip to content

Commit

Permalink
Demo of chapter 24 for 4th edition (aimacode#1105)
Browse files Browse the repository at this point in the history
* add demo of chapter 18

* add demo of chapter 24

* change naming convention

* rebuild
  • Loading branch information
bruceyoungsysu authored and delaray committed Sep 1, 2019
1 parent cf46b42 commit 19e4ae2
Show file tree
Hide file tree
Showing 11 changed files with 1,354 additions and 11 deletions.
408 changes: 408 additions & 0 deletions notebooks/chapter24/Image Edge Detection.ipynb

Large diffs are not rendered by default.

480 changes: 480 additions & 0 deletions notebooks/chapter24/Image Segmentation.ipynb

Large diffs are not rendered by default.

454 changes: 454 additions & 0 deletions notebooks/chapter24/Objects in Images.ipynb

Large diffs are not rendered by default.

Binary file added notebooks/chapter24/images/RCNN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added notebooks/chapter24/images/gradients.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added notebooks/chapter24/images/laplacian.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added notebooks/chapter24/images/laplacian_kernels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added notebooks/chapter24/images/stapler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added notebooks/chapter24/images/stapler_bbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 12 additions & 11 deletions perception4e.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,39 @@ def gradient_edge_detector(image):
:return: numpy ndarray, representing a gray scale image
"""
if not isinstance(image, np.ndarray):
img = np.asarray(image)
image = np.asarray(image)
# gradient filters of x and y direction edges
x_filter, y_filter = np.array([[1, -1]]), np.array([[1], [-1]])
# convolution between filter and image to get edges
y_edges = scipy.signal.convolve2d(img, x_filter, 'same')
x_edges = scipy.signal.convolve2d(img, y_filter, 'same')
y_edges = scipy.signal.convolve2d(image, x_filter, 'same')
x_edges = scipy.signal.convolve2d(image, y_filter, 'same')
edges = array_normalization(x_edges+y_edges, 0, 255)
return edges


def gaussian_derivative_edge_detector(image):
"""Image edge detector using derivative of gaussian kernels"""
if not isinstance(image, np.ndarray):
img = np.asarray(image)
image = np.asarray(image)
gaussian_filter = gaussian_kernel_2d()
# init derivative of gaussian filters
x_filter = scipy.signal.convolve2d(gaussian_filter, np.asarray([[1, -1]]), 'same')
y_filter = scipy.signal.convolve2d(gaussian_filter, np.asarray([[1], [-1]]), 'same')
# extract edges using convolution
y_edges = scipy.signal.convolve2d(img, x_filter, 'same')
x_edges = scipy.signal.convolve2d(img, y_filter, 'same')
y_edges = scipy.signal.convolve2d(image, x_filter, 'same')
x_edges = scipy.signal.convolve2d(image, y_filter, 'same')
edges = array_normalization(x_edges+y_edges, 0, 255)
return edges


def laplacian_edge_detector(image):
"""Extract image edge with laplacian filter"""
if not isinstance(image, np.ndarray):
img = np.asarray(image)
image = np.asarray(image)
# init laplacian filter
laplacian_kernel = np.asarray([[0, -1, 0], [-1, 4, -1], [0, -1, 0]])
# extract edges with convolution
edges = scipy.signal.convolve2d(img, laplacian_kernel, 'same')
edges = scipy.signal.convolve2d(image, laplacian_kernel, 'same')
edges = array_normalization(edges, 0, 255)
return edges

Expand Down Expand Up @@ -169,9 +169,10 @@ def group_contour_detection(image, cluster_num=2):
res = center[label.flatten()]
res2 = res.reshape((img.shape))
# show the image
cv2.imshow('res2', res2)
cv2.waitKey(0)
cv2.destroyAllWindows()
# cv2.imshow('res2', res2)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
return res2


def image_to_graph(image):
Expand Down

0 comments on commit 19e4ae2

Please sign in to comment.