Image Processing: Morphological Processing

Common basic morphological operations are:

skimage contains morphological operations optimized for 0-1 binary images, which can be implemented faster.

Bone extraction (image thinning/image thinning)

This is a kind of morphological processing. I used it when extracting the bones of handwriting, because the simple opening and closing operations between them can easily destroy the structural connectivity of the image. The bone extraction will refine the image under the premise of ensuring the structural connectivity.

API calls

scikit-imageThere are two implementations in the package, and the usage methods are as follows:

  • skimage.morphology.skeletonize: Can be used for bone extraction of 2D, 3D and ndarray images
  • skimage.morphology.thin: only for binary image
  • skimage.morphology.medial_axis: binary image, which is a collection of points with more than 1 closest point to the object boundary. Often referred to as topological bones .
from skimage import morphology
import cv2

img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)  # 转成灰度图
_, img_bin = cv2.threshold(img_gray, 100, 255, cv2.THRESH_BINARY_INV)  # 二值化处理
img_bin[img_bin == 255] = 1  # 将值变成0-1,骨骼提取函数必须要输入01的二值化图象
# 方法一 skeletonize
img_skeleton = morphology.skeletonize(img_bin)  # 骨骼提取
img = img_skeleton.astype(np.uint8) * 255  # 值从01重新映射回0-255
# 方法二 thin
img_thin = thin(img_bin)
img = img_thin.astype(np.uint8)
# 方法三 medial_axis
img_

application

  1. Handwriting refinement: When I recognize a mathematical formula, the recognition often confuses the plus sign and the division sign, so the formula image is refined, so that the two points of the division sign can be separated as much as possible, so that it will not be recognized as a plus sign . It works, but not much.

dilate

Corrosion (erode)

Open operation -> white top hat transformation

White top hat:

will return the bright spots in the image that are smaller than the structuring elements

Closed operation -> Black top hat transformation

For 0-1 binary images, faster closing operation:skimage.morphology.binary_closing

Black Top Hat: Closed Operation - Original Image

  • skimage.morphology.black_tophat

will return the black points in the image that are smaller than the structuring element

Guess you like

Origin blog.csdn.net/Jiangnan_Cai/article/details/127323342