Example Analysis of Digital Image processed by geometric Operation in Python
This article will explain in detail the example analysis of geometric operations in Python dealing with digital images. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Translation
# define translation matrix, need to be float32 type of numpy # x axis translation 50, y axis translation 80, 2x 3 matrix M = np.array ([[1,0,50], [0,1,80]], dtype=np.float32) # translate new_image = cv2.warpAffine (image, M, (w, h), borderValue= (0,0,0)) by affine transformation
Mirror image
Horizontal mirroring
# Flipped Horizontally horizontal Flip Horizontal = cv2.flip (image, 1)
Vertical mirroring
# Flipped Vertically Vertical Flip Vertical = cv2.flip (image, 0)
Rotation takes the upper left corner of the image as the center of rotation
# define rotation matrix, 2x3M = np.array ([np.cos (Beta), np.sin (Beta), 0], [- np.sin (Beta), np.cos (Beta), 0], dtype=np.float32) # realize rotation new_image = cv2.warpAffine (image, M, (w, h)) by affine transformation
Take the center of the image as the rotation center # define the rotation matrix, this time use the function cv2.getRotationMatrix2D (), where the first parameter is the center point of the rotation, the second is the rotation angle, and the third is the scaling ratio M = cv2.getRotationMatrix2D ((hash 2) print (M) # using affine transformation to achieve rotation new_image = cv2.warpAffine (image, M, (w, h), borderMode=cv2.BORDER_DEFAULT)
Scalin
New_image = cv2.resize (image, (0,0), fx=3, fy=3, interpolation=cv2.INTER_NEAREST)
Interpolation algorithm nearest neighbor interpolation algorithm cv2.INTER_NEAREST bilinear interpolation algorithm cv2.INTER_LINEAR cubic interpolation cv2.INTER_CUBIC on "geometric operations in Python processing digital image example analysis" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.