Morphological transformation of the image. Transform objects are generally grayscale or binary graphs, and function functions are placed within the morphology sub-module.
1, expansion (dilation)
Principle: Two value image is generally operated. Locate the point with a pixel value of 1 and set its neighboring pixels to this value. A value of 1 indicates white, and a value of 0 indicates black, so expansion operations can widen the range of white values and compress the black value range. Generally used to expand the edges or fill small holes.
function function:skimage.morphology. dilation (image, selem=none)
Selem represents a structural element used to set the shape and size of a local area.
fromSkimageImportDataImportskimage.morphology as SMImportMatplotlib.pyplot as Pltimg=Data.checkerboard () dst1=sm.dilation (Img,sm.square (5))#expansion filtering using a square filter with a side length of 5Dst2=sm.dilation (Img,sm.square (15))#expansion filtering using a square filter with a side length of 15Plt.figure ('morphology', Figsize= (8,8)) Plt.subplot (131) Plt.title ('Origin Image') plt.imshow (Img,plt.cm.gray) Plt.subplot (132) Plt.title ('Morphological Image') plt.imshow (Dst1,plt.cm.gray) Plt.subplot (133) Plt.title ('Morphological Image') plt.imshow (Dst2,plt.cm.gray)
The board image is expanded using a square filter with a side length of 5 or 15, with the following results:
The size of the visible filter has a very large effect on the operation result. Generally set to odd.
In addition to the square filter, the shape of the filter also has some, is listed as follows:
Morphology.square: Square
Morphology.disk: Flat Round
Morphology.ball: Spherical
Morphology.cube: Cube-shaped
Morphology.diamond: Diamond-shaped
Morphology.rectangle: Rectangle
Morphology.star: Star-shaped
Morphology.octagon: Octagonal
Morphology.octahedron: eight-face body
Note that if the processing image is a two-value image (only 0 and 12 values), you can call:
Skimage.morphology.binary_ dilation (image, Selem=none)
It is faster to use this function than to process grayscale images.
2. Corrosion (erosion)
Function:skimage.morphology. Erosion (image, selem=none)
Selem represents a structural element used to set the shape and size of a local area.
In contrast to the expansion, extend the 0 value to neighboring pixels. Enlarge the black part to reduce the white part. It can be used to extract the backbone information, remove the burr, and remove the isolated pixels.
fromSkimageImportDataImportskimage.morphology as SMImportMatplotlib.pyplot as Pltimg=Data.checkerboard () dst1=sm.erosion (Img,sm.square (5))#expansion filtering using a square filter with a side length of 5Dst2=sm.erosion (Img,sm.square (25))#expansion filtering using a square filter with a side length of 25Plt.figure ('morphology', Figsize= (8,8)) Plt.subplot (131) Plt.title ('Origin Image') plt.imshow (Img,plt.cm.gray) Plt.subplot (132) Plt.title ('Morphological Image') plt.imshow (Dst1,plt.cm.gray) Plt.subplot (133) Plt.title ('Morphological Image') plt.imshow (Dst2,plt.cm.gray)
Note that if the processing image is a two-value image (only 0 and 12 values), you can call:
skimage.morphology.binary_erosion (image, Selem=none)
It is faster to use this function than to process grayscale images.
3. Open operation (opening)
Function:skimage.morphology. openning (image, selem=none)
Selem represents a structural element used to set the shape and size of a local area.
The first corrosion and re-expansion, can eliminate small objects or small patches.
fromSkimageImportIo,colorImportskimage.morphology as SMImportMatplotlib.pyplot as Pltimg=color.rgb2gray (Io.imread ('D:/pic/mor.png')) DST=sm.opening (Img,sm.disk (9))#expansion filtering using a circular filter with a side length of 9Plt.figure ('morphology', Figsize= (8,8)) Plt.subplot (121) Plt.title ('Origin Image') plt.imshow (Img,plt.cm.gray) Plt.axis ('off') Plt.subplot (122) Plt.title ('Morphological Image') plt.imshow (Dst,plt.cm.gray) Plt.axis ('off')
Note that if the processing image is a two-value image (only 0 and 12 values), you can call:
Skimage.morphology.binary_ opening (image, Selem=none)
It is faster to use this function than to process grayscale images.
4, closed operation (closing)
Function:skimage.morphology. closing (image, selem=none)
Selem represents a structural element used to set the shape and size of a local area.
The first expansion and then corrosion, can be used to fill holes.
fromSkimageImportIo,colorImportskimage.morphology as SMImportMatplotlib.pyplot as Pltimg=color.rgb2gray (Io.imread ('D:/pic/mor.png')) DST=sm.closing (Img,sm.disk (9))#expansion filtering using a circular filter with a side length of 5Plt.figure ('morphology', Figsize= (8,8)) Plt.subplot (121) Plt.title ('Origin Image') plt.imshow (Img,plt.cm.gray) Plt.axis ('off') Plt.subplot (122) Plt.title ('Morphological Image') plt.imshow (Dst,plt.cm.gray) Plt.axis ('off')
Note that if the processing image is a two-value image (only 0 and 12 values), you can call:
Skimage.morphology.binary_ closing (image, Selem=none)
It is faster to use this function than to process grayscale images.
5. White Hat (White-tophat)
Function:skimage.morphology. White_tophat (image, selem=none)
Selem represents a structural element used to set the shape and size of a local area.
Subtract the original image from its open operation value and return the white point smaller than the structured element
fromSkimageImportIo,colorImportskimage.morphology as SMImportMatplotlib.pyplot as Pltimg=color.rgb2gray (Io.imread ('D:/pic/mor.png')) DST=sm.white_tophat (Img,sm.square (21)) Plt.figure ('morphology', Figsize= (8,8)) Plt.subplot (121) Plt.title ('Origin Image') plt.imshow (Img,plt.cm.gray) Plt.axis ('off') Plt.subplot (122) Plt.title ('Morphological Image') plt.imshow (Dst,plt.cm.gray) Plt.axis ('off')
6. Black Hat (Black-tophat)
Function:skimage.morphology. Black_tophat (image, selem=none)
Selem represents a structural element used to set the shape and size of a local area.
Subtracts the original image from its closed operation value, returns the black dots that are smaller than the structured element, and colors the black dots back.
fromSkimageImportIo,colorImportskimage.morphology as SMImportMatplotlib.pyplot as Pltimg=color.rgb2gray (Io.imread ('D:/pic/mor.png')) DST=sm.black_tophat (Img,sm.square (21)) Plt.figure ('morphology', Figsize= (8,8)) Plt.subplot (121) Plt.title ('Origin Image') plt.imshow (Img,plt.cm.gray) Plt.axis ('off') Plt.subplot (122) Plt.title ('Morphological Image') plt.imshow (Dst,plt.cm.gray) Plt.axis ('off')
Python Digital Image Processing (13): Basic Morphological filtering