Image operation and implementation of edge detection (python)

1. Classification of image operations

Image operations are divided into arithmetic operations and logical operations; arithmetic operations are generally used in grayscale images, which means that the grayscale values ​​of two pixels are obtained through arithmetic operations to obtain a new grayscale value as the corresponding result of the pixel at the same position in the new image. Gray value; arithmetic operations mainly include addition, subtraction, multiplication, and division. The logical operation refers to the gray value of the two pixels at the corresponding positions of the two original images to obtain a new gray value through logical operation, which is used as the gray value of the pixel at the same position in the corresponding new image. Therefore, the two images involved in the operation must be of equal size.

2. Implement arithmetic and logic operations

 3. Implement edge detection

A typical application of logic operations is edge detection. The edge detection algorithm based on logic operation includes the following six steps. Note: The algorithm is for two-dimensional images; for three-dimensional images, it needs to operate in 6 directions (left, right, up, down, front, back).

(1) Suppose the original image is figure (a) ;

(2) Move the pixel of figure (a) to the left by 1 pixel to obtain figure (b) ;

(3) Figure (a) and figure (b) are carried out logical OR operation to obtain figure (c) ;

(4) Figure (a) and Figure (c) are carried out logical XOR operation to obtain Figure (d) ;

(5) The above operation is performed on all 4 directions of left, right, up, down, up and down to obtain 4 result images, and logical OR operation is performed on the 4 result images to obtain the edge of the original image.

The reference code is as follows:

Guess you like

Origin blog.csdn.net/hu_666666/article/details/127212659