Image processing (Chapter 8, Image Segmentation, Threshold, Edge, Region, Binary Image Processing, Dilation, Corrosion, Open Operation, Close Operation, Mathematical Morphology)

Chapter 8 Image Segmentation

8.1 Image segmentation definition

(1) Definition of image segmentation The process of
dividing a digital image into disjoint (non-overlapping) regions

(2) Region definition
Connected set of pixels

(3) Connectivity definition
Between any two pixels in a connected set, there exists a connected path composed entirely of the elements of this set.

8.2 Using thresholds for image segmentation

8.2.1 Fixed threshold

(1) Definition
Set the gray threshold value in the entire image as a constant.

Prerequisite: If the gray value of the background can be reasonably regarded as constant in the entire image, and all objects and the background have almost the same contrast, then, as long as the correct threshold is selected, a fixed threshold will generally be more Good results.

8.2.2 Automatic threshold

Improved method of fixed threshold: Use automatic threshold.
In many cases, the gray value of the background is not constant , and the contrast between the object and the background changes in the image. At this time, a threshold that works well in one area of ​​the image may not work well in other areas. In this case, the gradation threshold value is taken as a position of the image with slowly varying in function value is suitable.

In some works, adaptive threshold is called dynamic threshold .

8.2.3 Optimal threshold

Unless the object in the image has a steep edge, the value of the gray threshold has a great influence on the location of the boundary of the extracted object and the overall size . This means that the subsequent size (especially area ) measurement is very sensitive to the choice of gray threshold . For this reason, we need an optimal, or at least a consistent method to determine the threshold.

8.2.3.1 Histogram technique

An image containing an object that is clearly contrasted with the background, which has a grayscale histogram containing double peaks
Insert picture description here

Histogram generation code imhist()

imhist ()

pic = imread('coins.png');%读图
%imshow(pic)显示原图
%figure窗体
hist_pic=imhist(pic)%显示直方图

or

pic=imread('coins.png');
subplot(121),imshow(pic),title('原图');
subplot(122),imhist(pic),title('直方图');

Insert picture description here
ps: imhist() directly displays the histogram, no need to add imshow

8.2.3.2 Maximum Between-Class Variance Method (OTSU)

Function in matlab: graythresh(), not on ppt, but it should be very common

(1) Definition
This algorithm is derived from the principle of the least square method on the basis of the gray histogram, and has the optimal segmentation threshold in a statistical sense.

(2) Principle
Divide the grayscale histogram of the image into two parts with the optimal threshold , and make the variance between the two parts take the maximum value , that is, the maximum separation .

Prerequisite: The threshold segmentation method for the two types of objects is realized under the premise that the gray distribution between the foreground and the background in the image does not overlap each other.

8.2.3.3 Iterative method for threshold

(1) Principle
Prerequisite: The threshold segmentation method for two types of objects is realized under the premise that the gray distribution between the foreground and the background in the image is not overlapped with each other.

8.2.4 Watershed segmentation algorithm

(1) Segmentation principle
Any grayscale image can be regarded as a topographic map.
Insert picture description here
(2) Define
the gradient of the watershed segmentation method applied to the image, then the watershed theoretically corresponds to the area with the smallest grayscale change, and The watershed corresponds to the area where the gray level changes relatively most.

(3) Disadvantages
Disadvantages: "Excessive segmentation" caused by noise or local irregularities

Insert picture description here
(4) Improve to
prevent "over-segmentation"
Insert picture description here
(5) Hierarchical segmentation
(1) Through the watershed algorithm, get an initial segmentation picture
(2) Based on these relative heights, use the watershed algorithm again

Use two watershed algorithms to get a better watershed segmentation map
Insert picture description here

8.3 Edge detection and connection

(1) Edge point
Another way to determine the boundary of an object in an image is to first detect the state of each pixel and its immediate neighborhood to determine whether the pixel is indeed on the boundary of an object. Pixels with the desired characteristics are marked as edge points.
(2) Edge image
When the gray level of each pixel in the image is used to reflect the degree to which each pixel meets the requirements of edge pixels, this kind of image is called an edge image.

8.3.1 Edge detection

The edge detection operator checks the neighborhood of each pixel and quantifies the gray-level change rate, usually including the determination of the direction. There are several methods that can be used, most of which are based on directional derivative mask convolution.
①Roherts edge operator②Sobel
edge operator③Prewitt
edge operator④Kirsch
edge operator

Effect picture:
Insert picture description here

8.3.2 Edge connection

(1) Problem
If the edge is obvious and the noise level is low, then the edge image can be binarized and refined into a single-pixel wide closed connected boundary image.
However, under non-ideal conditions, such edge images will have gaps that need to be filled.

(2) Solution
Filling small gaps can be achieved simply by searching for a 5×5 or larger neighborhood centered on a certain endpoint, finding other endpoints in the neighborhood and filling in the necessary boundary pixels, thereby Connect them.

However, for complex scenes with many edge points, this method may over-segment the image. In order to avoid excessive segmentation , it can be stipulated that the two endpoints can only be connected when the edge strength and direction are similar .

① Heuristic search
gap, two end points, find the global optimal path between the two end points (due to the complexity of heuristic search technology, it may not be able to find the optimal path)

②Curve fitting

③Hough transform

8.4 Region segmentation (region algorithm uses the similarity of pixels)

The region segmentation method uses the spatial nature of the image and considers the spatial relationship. The segmented pixels belonging to the same region have similar properties.
The more complex image space is realized by region segmentation technology.

8.4.1 Regional growth method (just understand)

Divided into:
(1) Simple connection
This is a single pixel-based area growth method. It starts from the satisfied detection point (connection core) and examines the surrounding (4 neighborhood or 8 neighborhood) that does not belong to any area. Point, if its characteristics meet the acceptance criteria, it is combined as the same area to form a connection core, and then the surrounding points are detected, and the points that meet the access criteria are merged to generate a new core. Repeat the above process until there are no points that can be merged, the production process ends.

(2) Sub-region merging method
Merging process:
First: divide the image into small regions (
referred to as sub-regions) of size.
Second: Starting from the first sub-area in the upper left corner, calculate
the gray-scale statistics of the sub- area and the adjacent sub-area respectively , and then make a
similarity judgment. If the gray distributions of the two are similar and meet
the acceptance criteria. Adjacent sub-areas are merged into the current sub-areas to
form the current sub-areas in the next round of judgment and merger.

8.4.1 Regional split and merge method (not in ppt)

8.5 Binary image processing

8.5.1 Mathematical Morphology Image Processing

ps: Open operation to remove small objects (corrosion and then expansion), close operation to connect gaps (expand and then corrosion)
Insert picture description here

Insert picture description here

8.5.1.1 Overview and basic knowledge of set theory (emphasis)

(1) Overview of Mathematical Morphology
Morphology: generally refers to a branch of biology that studies the structure of animals and plants

Mathematical morphology (also known as image algebra) represents a mathematical tool for analyzing images based on morphology

The basic idea: use structural elements with a certain shape to measure and extract the corresponding shapes in the image to achieve the purpose of image analysis and recognition

The mathematical foundation and language of morphological image processing is set theory

The application of morphological image processing can simplify image data, maintain their basic shape characteristics, and remove irrelevant structures

There are 4 basic operations in morphological image processing: expansion, erosion, opening operation and closing operation

8.5.1.2 Dilation

(1) Definition
Expansion: expand the image
B and S are two sets, B is defined by S expansion as:
D=B⊕S={ (x, y) | S(x, y) ∩ B ≠ ø}
Insert picture description here
ps: S(x,y)∩B means that when the center point is (x,y), the intersection of the structural element S and the original image B is not empty, or there is an intersection, then the center point should be marked as 1.

(2) Application

Bridging text cracks

Advantages: get the result directly in a binary image, compared with the low-pass filtering method.
The role of expansion: Connecting neighboring areas; filling small holes in the target area.

8.5.1.3 Corrosion

(1) Definition
Corrosion: to reduce the image
B and S are two sets, B is defined by S corrosion as:

        E=B Θ S={ (x, y) | S(x, y) ⊆ B }

Set S is called structural element
Insert picture description here

ps: S(x, y) ⊆ B is when the center point is (x, y), the structural element of S is entirely contained in the original image B, so mark the center point (x, y) as 1

(2) Application
The role of corrosion in mathematical morphological operations is to eliminate boundary points of objects.

If the structural element is a 3×3 pixel block, the erosion will reduce the boundary of the object by one pixel along the periphery.

Corrosion can remove objects smaller than structural elements (burrs, small bumps), so that by selecting structural elements of different sizes, objects of different sizes can be removed from the original image.

If there is a small connection between two objects, when the structural element is large enough, the two objects can be separated by the erosion operation.
Insert picture description here

8.5.1.4 Application

Boundary extraction, region filling, connected components, convex hull, thinning, coarsening

8.5.2 Open operation and close operation

8.5.2.1 Open operation

(1) Definition
The process of first corrosion and then expansion is called open operation.

(2) Function:
Eliminate small objects, separate objects at delicate points, and smooth the boundaries of larger objects without changing their area significantly.

8.5.2.2 Closed operation

(1) Definition
The process of first expansion and then corrosion is called closed operation.

(2) Function: It
fills small cavities in objects, connects neighboring objects, and smooths its boundaries without changing its area significantly.

8.5.3 Mathematical morphology application algorithm

8.5.3.1 Boundary extraction

Subtract the corrosion result from the original image
(1) Define
β (A)= A−(AΘB) The
above formula expresses: first corrodes A with B, then subtracts the corrosion with A, and B is a structural element

8.5.3.2 Area filling

(1) Definition
Definition: Set all non-boundary (background) points to be marked as 0, then assign 1 to point p to
Insert picture description here
achieve the goal: start from a point within the boundary and fill the entire area with 1

X 0 =p, if X k =X k-1 , the algorithm ends at the kth step of the iteration. The union of Xk and A includes the filled set and its boundary
condition expansion: if there is no restriction on the left part of the above formula, the expansion of the above formula will fill the entire area. The intersection of Ac is used to limit the result to the region of interest to achieve conditional expansion.
When filling the hole, A is the background area connected with the four borders of the image.

(2) Example
Eliminate the black dots in the white circle by area filling
Insert picture description here

pic=imread('circle.jpg');
BW1=im2bw(pic);%二值化
BW2=bwfill(BW1,'holes');%区域填充
imshow(BW2);%上图最右边那个就是效果图

8.5.3.3 Extraction of connected components

Extraction of skeleton

Guess you like

Origin blog.csdn.net/weixin_44575911/article/details/112710962