当前位置:网站首页>[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
边栏推荐
- Digital triangle model acwing 1018 Minimum toll
- Number of schemes from the upper left corner to the lower right corner of the chessboard (2)
- 2110 summary of knowledge points and common problems in redis class
- recyclerview gridlayout 平分中间空白区域
- 全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎
- I've seen many tutorials, but I still can't write a program well. How can I break it?
- use. Net analysis Net talent challenge participation
- 知识图谱构建流程步骤详解
- Web开发小妙招:巧用ThreadLocal规避层层传值
- 性能测试过程和计划
猜你喜欢

use. Net analysis Net talent challenge participation

Force deduction brush question - 98 Validate binary search tree

“罚点球”小游戏

Build your own application based on Google's open source tensorflow object detection API video object recognition system (IV)
![[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100

Introduction of Xia Zhigang

01 基础入门-概念名词

Quel genre de programmation les enfants apprennent - ils?

02 basic introduction - data package expansion

Variable star --- article module (1)
随机推荐
Statistical inference: maximum likelihood estimation, Bayesian estimation and variance deviation decomposition
Can novices speculate in stocks for 200 yuan? Is the securities account given by qiniu safe?
C language games - three chess
1_ Introduction to go language
In unity space, an object moves around a fixed point on the sphere at a fixed speed
Kubernetes learning summary (20) -- what is the relationship between kubernetes and microservices and containers?
C language operators
过程化sql在定义变量上与c语言中的变量定义有什么区别
华为设备命令
【微信小程序】运行机制和更新机制
Design your security architecture OKR
Leetcode hot topic Hot 100 day 32: "minimum coverage substring"
Utilisation de l'écran OLED
Detailed explanation of knowledge map construction process steps
Error analysis ~csdn rebound shell error
How to turn a multi digit number into a digital list
[DIY]如何制作一款個性的收音機
Unity load AB package
Quel genre de programmation les enfants apprennent - ils?
Detailed introduction of distributed pressure measurement system VIII: basic introduction of akka actor model