[200 OpenCV routines of youcans] 135. Granularity determination of morphological reconstruction

Welcome to the "youcans' OpenCV routines 200" series, continue to update
welcome to pay attention to the "youcans' OpenCV learning course" series, which is continuously updated


[200 OpenCV routines of youcans] 135. Granularity determination of morphological reconstruction

4. Morphological Image Reconstruction

The core of morphological reconstruction is geodesic dilation and geodesic erosion.

Morphological reconstruction of an image involves two images and a structuring element: image F is a marker, containing the starting point of the reconstruction; image G is a template, used to constrain the reconstruction; structuring element B defines connectivity, usually a 3*3 array of all 1s .

In binary images, geodesic erosion or geodesic dilation is the intersection operation (and) or union operation (or) between the erosion or dilation result and the template image G, and the generalization in grayscale images is to find the maximum value , the minimum value to replace the binary AND-OR operation.

Simply put, geodesic expansion and geodesic corrosion are conditional expansion and corrosion. The dilation or erosion result is intersected or unioned with the template image, thereby imposing specific constraints on the dilation or erosion operation.


4.5 Morphological particle size determination

Particle size determination is in the field of determining the size distribution of particles in an image.

For a binary image I ( x , y ) I(x,y)I(x,y ) , develop an algorithm for particle size determination based on morphological reconstruction.


Routine 10.25: Particle size determination based on morphological reconstruction

This example is a particle size determination based on morphological reconstruction.

    # 10.25: 基于形态学重建的粒度测定
    imgGray = cv2.imread("../images/Fig0941a.tif", flags=0)  # flags=0 灰度图像
    ret, imgBin = cv2.threshold(imgGray, 127, 255, cv2.THRESH_BINARY)  # 二值化处理 (黑色背景), 本例等效于原图像
    imgBinInv = cv2.bitwise_not(imgBin)  # 二值图像的补集 (白色背景)

    # 构造标记图像: 采用图像的腐蚀结果作为膨胀重建的标记
    element = cv2.getStructuringElement(cv2.MORPH_RECT, (1,50), (-1,-1))  # 特征结构元,50 像素点为特征高度
    imgErode = cv2.erode(imgBin, kernel=element)  # 对原图像(黑色背景)腐蚀,作为标记图像

    # 形态学重建
    mask = imgBin  # 原图像 (黑色背景) 作为掩模
    marker = imgErode  # 腐蚀结果作为重建的标记
    element = cv2.getStructuringElement(cv2.MORPH_CROSS, (3,3))
    while True:
        marker_pre = marker  # 保存 F(n-1)
        dilation = cv2.dilate(marker, kernel=element)  # 膨胀重建
        marker = cv2.bitwise_and(dilation, mask)  # 原图像作为模板用来约束重建,按位与,有 0 得 0
        if (marker_pre == marker).all():  # F(n)=F(n-1)?,判断是否达到稳定收敛状态
            break
    imgRebuild = marker  # 最终的 marker 就是重建开运算的结果
    imgDual = cv2.bitwise_not(imgBinInv + marker)  # 重建开运算的对偶结果,不含竖线的字母

    # 显示
    plt.figure(figsize=(9, 7))
    plt.subplot(231), plt.imshow(imgGray, cmap='gray'), plt.title("origin image"), plt.axis("off")
    plt.subplot(232), plt.imshow(imgBin, cmap='gray'), plt.title("binary image"), plt.axis("off")
    plt.subplot(233), plt.imshow(imgBinInv, cmap='gray'), plt.title("binary invert"), plt.axis("off")
    plt.subplot(234), plt.imshow(imgErode, cmap='gray'), plt.title("eroded image"), plt.axis("off")
    plt.subplot(235), plt.imshow(imgRebuild, cmap='gray'), plt.title("rebuild image"), plt.axis("off")
    plt.subplot(236), plt.imshow(imgDual, cmap='gray'), plt.title("dual rebuild"), plt.axis("off")
    plt.tight_layout()
    plt.show()

insert image description here


(End of this section)


Copyright Notice:

Youcans@xupt original works, reprints must be marked with the original link: (https://blog.csdn.net/youcans/article/details/123527157)

Copyright 2022 youcans, XUPT
Crated:2022-3-18


Welcome to the "youcans' OpenCV routines 200" series, continue to update
welcome to pay attention to the "youcans' OpenCV learning course" series, which is continuously updated

[Youcans's OpenCV routines 200] 01. Image reading (cv2.imread)
[youcans's OpenCV routines 200] 02. Image saving (cv2.imwrite)
[youcans's OpenCV routines 200] 03. Image display (cv2.imshow)
[youcans' OpenCV routines 200] 04. Display images with matplotlib (plt.imshow)
[youcans's OpenCV routines 200] 05. Image attributes (np.shape)
[youcans' 200 OpenCV routines] 06. Pixel editing (img.itemset)
[youcans's OpenCV routines 200] 07. Image creation (np.zeros)
[youcans's OpenCV routines 200] 08. Image duplication ( np.copy)
[Youcans's OpenCV routines 200] 09. Image cropping (cv2.selectROI)
[youcans's OpenCV routines 200] 10. Image stitching (np.hstack)
[youcans's OpenCV routines 200 ] 11. Splitting of image channels (cv2.split)
[200 OpenCV routines of youcans] 12. Merging of image channels (cv2.merge)
[200 OpenCV routines of youcans] 13. Image addition (cv2 .add )
[200 OpenCV routines of youcans] 14. Image and scalar addition (cv2.add)
[200 OpenCV routines of youcans] 15. Weighted addition of images (cv2.addWeight)
[200 OpenCV routines of youcans] 16. Image addition of different sizes
[200 OpenCV routines of youcans] 17. Two images Gradient switching
[youcans's OpenCV routines 200] 18. Image mask addition
[youcans's OpenCV routines 200] 19. Image circular mask
[youcans's OpenCV routines 200] 20. Image press Bit operation
[youcans's OpenCV routines 200] 21. Image overlay
[youcans's OpenCV routines 200] 22. Image adding non-Chinese text
[youcans's OpenCV routines 200] 23. Image adding Chinese text
[youcans's 200 OpenCV routines] 24. Affine transformation of images
[youcans's OpenCV routines 200] 25. Image translation
[youcans's OpenCV routines 200] 26. Image rotation (centered on the origin)
[youcans's 200 OpenCV routines] 27. Image rotation (centered on any point)
[youcans's OpenCV routines 200] 28. Image rotation (right-angle rotation)
[youcans's OpenCV routines 200] 29. Image flip (cv2.flip)
[200 OpenCV routines of youcans] 30. Image scaling (cv2.resize)
[Youcans's OpenCV routines 200] 31. Image pyramid (cv2.pyrDown)
[youcans's OpenCV routines 200] 32. Image distortion (miscut)
[youcans's OpenCV routines 200] 33. Image Compound transformation
[youcans's OpenCV routines 200] 34. Image projection transformation
[youcans's OpenCV routines 200] 35. Image projection transformation (boundary filling)
[youcans's OpenCV routines 200] 36. Cartesian coordinates and Polar coordinate conversion
[youcans's OpenCV routines 200] 37. Image grayscale processing and binarization
[youcans's OpenCV routines 200] 38. Image inverse color transformation (image inversion)
[youcans's OpenCV routines 200 articles] 39. Linear transformation of image grayscale
[youcans's OpenCV routines 200 articles] 40. Image piecewise linear grayscale transformation
[youcans's OpenCV routines 200 articles] 41. Image grayscale transformation (gray Degree level layering)
[youcans's OpenCV routines 200] 42. Image grayscale transformation (bit plane layering)
[youcans's OpenCV routines 200] 43. Image grayscale transformation (logarithmic transformation)
[youcans 200 articles of OpenCV routines] 44. Grayscale transformation of images (gamma transformation)
[200 articles of OpenCV routines of youcans] 45. Grayscale histogram of images
[200 articles of OpenCV routines of youcans] 46. Histogram equalization change
[Youcans's OpenCV routines 200 articles] 47. Image enhancement - histogram matching
[youcans's OpenCV routines 200 articles] 48. Image enhancement - color histogram matching
[youcans's OpenCV routines 200 articles] 49. Image enhancement - local Histogram processing
[youcans's OpenCV routines 200 articles] 50. Image enhancement - histogram statistics image enhancement
[youcans's OpenCV routines 200 articles] 51. Image enhancement - histogram reverse tracking
[youcans's OpenCV routines 200 articles ] ] 52. Image correlation and convolution operations
[youcans's OpenCV routines 200] 53. Scipy implements two-dimensional image convolution
[youcans's OpenCV routines 200] 54. OpenCV implements image two-dimensional convolution
[youcans's OpenCV 200 routines] 55. Separable convolution kernel
[youcans's OpenCV routines 200] 56. Low-pass box filter
[youcans's OpenCV routines 200] 57. Low-pass Gaussian filter
[youcans's OpenCV example ] Cheng 200 articles] 58. Nonlinear filtering - median filtering
[youcans's OpenCV routines 200 articles] 59. Non-linear filtering - bilateral filtering
[youcans's OpenCV routines 200 articles] 60. Nonlinear filtering - joint bilateral filtering
[youcans 200 articles of OpenCV routines] 61. Guided filter
[200 articles of OpenCV routines of youcans] 62. Image sharpening - passivation masking
[Youcans's OpenCV routines 200] 63. Image sharpening - Laplacian operator
[youcans's OpenCV routines 200] 64. Image sharpening - Sobel operator
[youcans's OpenCV routines 200] 65. Image Sharpening - Scharr operator
[youcans's OpenCV routines 200] 66. Image filtering low-pass/high-pass/band-stop/band-pass
[youcans's OpenCV routines 200] 67. Comprehensive application of spatial domain image enhancement
[ Youcans's OpenCV routines 200 articles] 68. Comprehensive application of spatial domain image enhancement
[youcans's OpenCV routines 200 articles] 69. Fourier coefficients of continuous non-periodic signals
[youcans's OpenCV routines 200 articles] 70. One-dimensional continuous function Fourier transform of
[youcans's OpenCV routines 200] 71. Sampling of continuous functions
[youcans's OpenCV routines 200] 72. One-dimensional discrete Fourier transform
[youcans's OpenCV routines 200] 73. Two Dimensional continuous Fourier transform
[youcans's OpenCV routines 200] 74. Image anti-aliasing
[youcans's OpenCV routines 200] 75. Numpy implements image Fourier transform
[youcans's OpenCV routines 200] 76 . OpenCV implements image Fourier transform
[youcans's OpenCV routines 200] 77. OpenCV implements fast Fourier transform
[Youcans's OpenCV routines 200 articles] 78. Basics of frequency domain image filtering
[youcans's OpenCV routines 200 articles] 79. Basic steps of frequency domain image filtering
[youcans's OpenCV routines 200 articles] 80. Frequency domain image filtering in detail Steps
[youcans's OpenCV routines 200] 81. Frequency domain Gaussian low-pass filter
[youcans's OpenCV routines 200] 82. Frequency domain Butterworth low-pass filter
[youcans's OpenCV routines 200] 83. Frequency domain low-pass filtering: repairing printed text characters
[youcans's OpenCV routines 200] 84. Obtaining high-pass filters from low-pass filters
[youcans's OpenCV routines 200] 85. Application of frequency-domain high-pass filters
[youcans 200 articles of OpenCV routines] 86. Application of frequency domain filtering: fingerprint image processing
[200 articles of OpenCV routines of youcans] 87. Passivation masking of frequency domain
[200 articles of OpenCV routines of youcans] 88. Laplacian of frequency domain High-pass filtering
[youcans' OpenCV routines 200] 89. Transfer function of band-stop filter
[youcans's OpenCV routines 200] 90. Frequency domain notch filter
[youcans's OpenCV routines 200] 91. Gaussian noise , Rayleigh noise, Irish noise
[youcans's OpenCV routines 200] 92. Exponential noise, uniform noise, salt and pepper noise
[youcans's OpenCV routines 200] 93. Histogram of the noise model
[Youcans's OpenCV routines 200] 94. Arithmetic mean filter
[youcans's OpenCV routines 200] 95. Geometric mean filter
[youcans's OpenCV routines 200] 96. Harmonic averaging filter
[youcans's OpenCV 200 routines] 97. Inverse harmonic averaging filter
[youcans's OpenCV routines 200] 98. Statistical sorting filter
[youcans's OpenCV routines 200] 99. Corrected alpha mean filter
[youcans's OpenCV routines ] 200 articles] 100. Adaptive local noise reduction filter
[youcans's OpenCV routines 200 articles] 101. Adaptive median filter
[youcans's OpenCV routines 200 articles] 102. The transfer function of the notch band-stop filter
[ Youcans's OpenCV routines 200] 103. Notch band-stop filter to eliminate periodic noise interference
[youcans's OpenCV routines 200] 104. Motion blur degradation model
[youcans's OpenCV routines 200] 105. Turbulence blur degradation model
[Youcans's OpenCV routines 200] 106. Inverse filtering of degraded images
[youcans's OpenCV routines 200] 107. Wiener filtering of degraded images
[youcans's OpenCV routines 200] 108. Constrained least squares filtering
[200 OpenCV routines of youcans] 109. Geometric mean filtering
[Youcans's OpenCV routines 200 articles] 110. Projection and Raiden transform
[youcans's OpenCV routines 200 articles] 111. Raiden transform back-projection reconstructed images
[youcans's OpenCV routines 200 articles] 112. Filtered back-projection reconstructed images
[200 OpenCV routines by youcans] 113. Corrosion of morphological operations
[200 OpenCV routines by youcans] 114.
Dilation of morphological operations [200 OpenCV routines by youcans] 115. Open operation of morphological operations
[ Youcans's OpenCV routines 200 articles] 116. The closed operation of morphological operations
[youcans's OpenCV routines 200 articles] 117. The top hat operation of morphological operations
[youcans's OpenCV routines 200 articles] 118. The bottom of morphological operations Hat operation
[youcans's OpenCV routines 200 articles] 119. Morphological gradients of images
[youcans's OpenCV routines 200 articles] 120. hit-hit-miss transformation
[youcans's OpenCV routines 200 articles] 121. hit- Missed for feature recognition
[youcans' OpenCV routines 200] 122. Boundary extraction of morphological algorithms
[youcans's OpenCV routines 200] 123. Hole filling of morphological algorithms
[youcans's OpenCV routines 200] 124. Flooding algorithm for hole filling
[200 OpenCV routines of youcans] 125. Extraction of connected components by morphological algorithm
[Youcans's OpenCV routines 200] 126. Convex hull of morphological algorithms
[youcans's OpenCV routines 200] 127. Refinement of morphological algorithms
[youcans's OpenCV routines 200] 128. The skeleton of the morphological algorithm (skimage)
[Youcans's OpenCV routines 200] 129. The skeleton of the morphological algorithm (reconstruction operation)
[youcans's OpenCV routines 200] 130. Morphological extraction of horizontal and vertical lines
[youcans's OpenCV routines 200] 131. Vertical line character extraction of morphological reconstruction
[youcans's OpenCV routines 200] 132. Morphological reconstruction of the hole filling algorithm
[youcans's OpenCV routines 200] 133. Morphological reconstruction of the boundary clearing
[youcans's OpenCV routines 200 ] Article] 134. Cell counting of morphological reconstruction
[200 OpenCV routines of youcans] 135. Granularity determination of morphological reconstruction

Guess you like

Origin blog.csdn.net/youcans/article/details/123527157