当前位置:网站首页>[200 opencv routines] 220 Mosaic the image
[200 opencv routines] 220 Mosaic the image
2022-07-06 20:42:00 【Xiaobai youcans】
List of articles :『youcans Of OpenCV routine 200 piece - General catalogue 』
【youcans Of OpenCV routine 200 piece 】220. Mosaic the image
9. Mosaic processing of image
Mosaic effect is a widely used image and video processing method . Degrade the color scale details of the specified area in the image , Cause the effect of color block blur , It looks like a color block composed of small squares , Called mosaic . The main purpose of mosaic effect is to make the details of specific areas unrecognizable , It is often used to cover people's faces 、 Privacy information .
The mosaic method is very simple , Divide the processing area into small blocks , Set all pixels in each small square to the same or similar pixel values . routine A4.13 A simple implementation case is given .
The larger the size of the mosaic square , The more blurred the image , The more details the mosaic area image loses .
This is similar to image multiscale pixel sampling : Image down sampling , The resolution decreases step by step . Mosaic the whole image , It is equivalent to image down sampling ; Mosaic the part of the image , It is equivalent to the fusion of down sampling of the original image and local image .
Up sampling and down sampling are irreversible , High frequency information will be lost when the down sampled image is restored to its original size , Blur the picture . therefore , It is impossible in principle to eliminate image mosaic . however , Filling algorithm through interpolation of adjacent points of picture pixels , It can enhance the visual effect of mosaic area . In recent years , With AI Technological development , Based on learning a large number of similar clear images , Use AI The algorithm can restore the image better , Recognize faces or texts blocked by mosaics , Good results were achieved .
routine A4.13: Mosaic the specified area of the image
For the selected ROI Mosaic the area . The larger the size of the mosaic square , The more blurred the image , The more details the mosaic area image loses .
# A4.13 Mosaic the specified area of the image
img = cv.imread("../images/imgLena.tif", 1) # Load the original image , single channel
roi = cv.selectROI(img, showCrosshair=True, fromCenter=False)
x, y, wRoi, hRoi = roi # Position parameters of rectangular clipping region
# x, y, wRoi, hRoi = 208, 176, 155, 215 # Rectangular crop region
imgROI = img[y:y+hRoi, x:x+wRoi].copy() # Slice to get a rectangular clipping region
print(x, y, wRoi, hRoi)
plt.figure(figsize=(9, 6))
plt.subplot(231), plt.title("Original image"), plt.axis('off')
plt.imshow(cv.cvtColor(img, cv.COLOR_BGR2RGB))
plt.subplot(232), plt.title("Region of interest"), plt.axis('off')
plt.imshow(cv.cvtColor(imgROI, cv.COLOR_BGR2RGB))
mosaic = np.zeros(imgROI.shape, np.uint8) # ROI Area
ksize = [5, 10, 20] # Width of mosaic block
for i in range(3):
k = ksize[i]
for h in range(0, hRoi, k):
for w in range(0, wRoi, k):
color = imgROI[h,w]
mosaic[h:h+k,w:w+k,:] = color # Cover the mosaic block with vertex color
imgMosaic = img.copy()
imgMosaic[y:y + hRoi, x:x + wRoi] = mosaic
plt.subplot(2,3,i+4), plt.title("Coding image (size={})".format(k)), plt.axis('off')
plt.imshow(cv.cvtColor(imgMosaic, cv.COLOR_BGR2RGB))
plt.subplot(233), plt.title("Mosaic"), plt.axis('off')
plt.imshow(cv.cvtColor(mosaic, cv.COLOR_BGR2RGB))
plt.show()
【 At the end of this section 】
Copyright notice :
[email protected] Original works , Reprint must be marked with the original link :(https://blog.csdn.net/youcans/article/details/125522759)
Copyright 2022 youcans, XUPT
Crated:2022-6-30
218. Multi line oblique text watermark
219. Add digital blind watermark
220.220. Mosaic the image
边栏推荐
- 8086 instruction code summary (table)
- 小孩子学什么编程?
- 2022 refrigeration and air conditioning equipment installation and repair examination contents and new version of refrigeration and air conditioning equipment installation and repair examination quest
- Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]
- [asp.net core] set the format of Web API response data -- formatfilter feature
- Rhcsa Road
- I've seen many tutorials, but I still can't write a program well. How can I break it?
- "Penalty kick" games
- Use of OLED screen
- “罚点球”小游戏
猜你喜欢
[DIY]自己设计微软MakeCode街机,官方开源软硬件
Intel 48 core new Xeon run point exposure: unexpected results against AMD zen3 in 3D cache
Utilisation de l'écran OLED
02 基础入门-数据包拓展
[wechat applet] operation mechanism and update mechanism
Pytest (3) - Test naming rules
Core principles of video games
Logic is a good thing
Force deduction brush question - 98 Validate binary search tree
2022 construction electrician (special type of construction work) free test questions and construction electrician (special type of construction work) certificate examination
随机推荐
解剖生理学复习题·VIII血液系统
SSO single sign on
How to upgrade high value-added links in the textile and clothing industry? APS to help
C language games - three chess
Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
Zoom with unity mouse wheel: zoom the camera closer or farther
Gui Gui programming (XIII) - event handling
2022 nurse (primary) examination questions and new nurse (primary) examination questions
Notes on beagleboneblack
【每周一坑】输出三角形
2022 Guangdong Provincial Safety Officer C certificate third batch (full-time safety production management personnel) simulation examination and Guangdong Provincial Safety Officer C certificate third
Discussion on beegfs high availability mode
小孩子学什么编程?
Leetcode question 448 Find all missing numbers in the array
Special topic of rotor position estimation of permanent magnet synchronous motor -- fundamental wave model and rotor position angle
Use of OLED screen
Le lancement du jupyter ne répond pas après l'installation d'Anaconda
拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条
【DSP】【第二篇】了解C6678和创建工程
In line elements are transformed into block level elements, and display transformation and implicit transformation