Welcome to ROSMASTER X3 Plus repository
9.4 Image beautification
4. Open Source CV image beautification
4. Open Source CV image beautification 4.1. OpenCV repair image 4.2. OpenCV image brightness enhancement 4.3. OpenCV image microdermabrasion and whitening
4.1. OpenCV repair image
- Image inpainting is a class of algorithms in computer vision whose goal is to fill areas within an image or video. The area is identified using a binary mask, and filling is usually done according to the area boundary information that needs to be filled. The most common application of image restoration is to restore old scanned photos. It is also used to remove small unwanted objects in images.
- In OpenCV, dst = cv2.inpaint(src, inpaintMask, inpaintRadius, flags) is provided to repair the image,
Parameter meaning:
src: source image, which is the image that needs to be repaired
inpaintMask: Binary mask indicating the pixels to be inpainted.
dst: result image
inpaintRadius: Indicates the radius of the repair
flags : Repair algorithm, mainly INPAINT_NS (Navier-Stokes based method) or INPAINT_TELEA (Fast marching based method)
Navier-Stokes based fixes should be slower and tend to produce more ambiguous results than fast marching methods. In practice, we have not found this to be the case. INPAINT_NS produced better results in our tests and was also slightly faster than INPAINT_TELEA.
- Code and actual effect display
(1) First, we first add damage to the intact picture, which can be understood as modifying the pixel value of a specific part of it
run the program
xpython ~/yahboomcar_ws/src/yahboomcar_astra/scripts/opencv/4_1_1.py
ximport cv2import numpy as npif __name__ == '__main__':img = cv2.imread('yahboom.jpg')for i in range(50,100):img[i,50] = (0,0,0)img[i,50+1] = (0,0,0)img[i,50-1] = (0,0,0)for i in range(100,150):img[150,i] = (0,0,0)img[150,i+1] = (0,0,0)img[150-1,i] = (0,0,0)cv2.imwrite("damaged.jpg",img)dam_img = cv2.imread('damaged.jpg')while True :cv2.imshow("dam_img",dam_img)action = cv2.waitKey(10) & 0xFFif action == ord('q') or action == 113:breakimg.release()cv2.destroyAllWindows()
After running, a picture will be generated, which is regarded as a damaged picture of the original picture.