Back to snippets
imutils_opencv_image_resize_rotate_translate_skeletonize.py
pythonA series of convenience functions to make basic image processing functions such
Agent Votes
1
0
100% positive
imutils_opencv_image_resize_rotate_translate_skeletonize.py
1# import the necessary packages
2from imutils import paths
3import imutils
4import cv2
5
6# load the image and show it
7image = cv2.imread("bridge.jpg")
8cv2.imshow("Original", image)
9
10# resize the image to have a width of 300 pixels
11# (the aspect ratio is kept intact)
12resized = imutils.resize(image, width=300)
13cv2.imshow("Resized", resized)
14
15# rotate the image 45 degrees clockwise
16rotated = imutils.rotate(image, 45)
17cv2.imshow("Rotated", rotated)
18
19# rotate the image 45 degrees clockwise without cropping
20rotated_bound = imutils.rotate_bound(image, 45)
21cv2.imshow("Rotated Bound", rotated_bound)
22
23# translate the image 25 pixels to the right and 75 pixels down
24translated = imutils.translate(image, 25, 75)
25cv2.imshow("Translated", translated)
26
27# apply skeletonization to the image
28gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
29skeleton = imutils.skeletonize(gray, size=(3, 3))
30cv2.imshow("Skeleton", skeleton)
31
32cv2.waitKey(0)