一种图像的处理方法和装置Image processing method and device技术领域Technical field本文涉及摄像领域,具体涉及图像的处理方法和装置。This paper relates to the field of imaging, and specifically relates to an image processing method and apparatus.
背景技术Background technique随着智能终端的普及,手机的拍照功能成为了用户选择购买手机的重要参考因素之一。拍照模式有多样化,包括:自动、夜间、美肤等模式,每种拍照模式都是针对性的处理照片。大多数拍照处理都是帮助用户拍摄更好的图片,很少人关注对成像质量差的图片进行处理。幼儿常会拿手机玩着拍照,很多照片都是很模糊的;家长在给孩子拍照时,小孩子经常乱动,也会拍出很多模糊的照片家长需要一张一张删除没有保存价值的模糊照片。With the popularity of smart terminals, the camera function of mobile phones has become one of the important reference factors for users to choose to purchase mobile phones. There are a variety of camera modes, including: automatic, night, skin and other modes, each of which is targeted to process photos. Most of the photo processing is to help users take better pictures, and few people pay attention to the processing of images with poor image quality. Children often take pictures with their mobile phones, and many photos are very vague; when parents are taking pictures of children, children often tamper with them, and they will also take a lot of blurred photos. Parents need to delete the blurred photos without saving value. .
目前的终端大都是针对防抖技术进行改进,而没有对模糊照片进行处理,但防抖技术并不能完全解决上述问题,用户手动一个一个删除模糊没有保存价值的照片,浪费时间。At present, most of the terminals are improved for the anti-shake technology, but the fuzzy photos are not processed, but the anti-shake technology can not completely solve the above problems, and the user manually deletes the photos without blurring the value, which wastes time.
发明内容Summary of the invention
本发明实施例提供了一种图像的处理方法和装置,以解决如何实现终端自动识别模糊图像的功能,避免用户逐个筛选没有保存价值的模糊图像的技术问题。The embodiment of the invention provides an image processing method and device, which solves the problem of how to realize the function of automatically recognizing a blurred image by the terminal, and avoids the technical problem of the user filtering the blurred image without saving value one by one.
为了解决上述技术问题,本申请提供了一种图像的处理方法,所述方法包括:In order to solve the above technical problem, the present application provides a method for processing an image, the method comprising:
获取图像每个像素点的灰度值,根据预设的N个灰度等级,将所述图像划分为一个或多个区域,同一区域中的每个像素点属于同一灰度等级,N为大于或者等于1的正整数;Obtaining a gray value of each pixel of the image, and dividing the image into one or more regions according to the preset N gray levels, each pixel in the same region belongs to the same gray level, and N is greater than Or a positive integer equal to 1;
计算所述图像划分的每个区域的面积,确定面积最大的区域,并计算所述图像的灰度等级的个数;Calculating an area of each area of the image division, determining an area having the largest area, and calculating a number of gray levels of the image;
根据所述面积最大的区域的面积和/或所述图像的灰度等级的个数判断所述图像是否为模糊图像。Whether the image is a blurred image is determined according to the area of the area having the largest area and/or the number of gray levels of the image.
可选地,Optionally,
根据所述面积最大的区域的面积和/或所述图像的灰度等级的个数判断所述图像是否为模糊图像包括:Determining whether the image is a blurred image according to an area of the area having the largest area and/or a number of gray levels of the image includes:
当面积最大的区域的面积与所述图像的全部面积的比值大于或等于第一阈值时,将所述图像作为模糊图像,或者当面积最大的区域的面积与图像的全部面积的比值小于第一阈值且当所述图像的灰度等级的个数小于或等于第二阈值时,将所述图像作为模糊图像。When the ratio of the area of the area having the largest area to the total area of the image is greater than or equal to the first threshold, the image is regarded as a blurred image, or the ratio of the area of the area having the largest area to the total area of the image is smaller than the first The threshold and when the number of gray levels of the image is less than or equal to the second threshold, the image is taken as a blurred image.
可选地,Optionally,
将所述图像中属于同一个灰度等级且相邻的像素点划分为一个区域;所述图像的灰度等级的个数小于或者等于N;Subdividing pixel points belonging to the same gray level and adjacent pixels into one area; the number of gray levels of the image is less than or equal to N;
所述第一阈值为80%,所述第二阈值为2。The first threshold is 80% and the second threshold is 2.
可选地,Optionally,
所述N为5,所述图像每个像素点的灰度值的取值范围为0至255,所述预设的N个灰度等级是指将所述灰度值的取值范围分为5个区间,每个区间对应一个灰度等级。The N is 5, and the gray value of each pixel of the image ranges from 0 to 255, and the preset N gray levels refers to dividing the value range of the gray value into 5 intervals, each corresponding to a gray level.
可选地,所述方法还包括:Optionally, the method further includes:
将所述图像作为模糊图像后,将所述模糊图像删除。After the image is taken as a blurred image, the blurred image is deleted.
本发明实施例还提供一种图像的处理装置,所述装置包括:An embodiment of the present invention further provides an image processing apparatus, where the apparatus includes:
预处理模块,设置为获取图像每个像素点的灰度值,根据预设的N个灰度等级,将所述图像划分为一个或多个区域,同一区域中的每个像素点属于同一灰度等级,N为大于或者等于1的正整数;The preprocessing module is configured to acquire a gray value of each pixel of the image, and divide the image into one or more regions according to the preset N gray levels, and each pixel in the same region belongs to the same gray Degree level, N is a positive integer greater than or equal to 1;
计算模块,设置为计算所述图像划分的每个区域的面积,确定面积最大的区域;还设置为计算所述图像的灰度等级的个数;a calculation module, configured to calculate an area of each area of the image division, determine an area with the largest area; and further set to calculate a number of gray levels of the image;
判断模块,设置为根据所述面积最大的区域的面积和/或所述图像的灰度等级的个数判断所述图像是否为模糊图像。a judging module configured to be based on an area of the area having the largest area and/or a gray scale of the imageThe number of levels determines whether the image is a blurred image.
可选地,Optionally,
判断模块设置为通过如下方式实现根据所述面积最大的区域的面积或所述图像的灰度等级的个数判断所述图像是否为模糊图像:The judging module is configured to determine whether the image is a blurred image according to an area of the area with the largest area or a number of gray levels of the image by:
当面积最大的区域的面积与所述图像的全部面积的比值大于或等于第一阈值时,将所述图像作为模糊图像;或当面积最大的区域的面积与图像的全部面积的比值小于第一阈值且当所述图像的灰度等级的个数小于或等于第二阈值时,将所述图像作为模糊图像。When the ratio of the area of the area with the largest area to the total area of the image is greater than or equal to the first threshold, the image is regarded as a blurred image; or the ratio of the area of the area with the largest area to the total area of the image is smaller than the first The threshold and when the number of gray levels of the image is less than or equal to the second threshold, the image is taken as a blurred image.
可选地,Optionally,
预处理模块,是设置为将所述图像中属于同一个灰度等级且相邻的像素点划分为一个区域;所述图像的灰度等级的个数小于或者等于N;The preprocessing module is configured to divide adjacent pixels of the image into the same gray level into one region; the number of gray levels of the image is less than or equal to N;
所述第一阈值为80%,所述第二阈值为2。The first threshold is 80% and the second threshold is 2.
可选地,Optionally,
所述N为5,所述图像每个像素点的灰度值的取值范围为0至255,所述预设的N个灰度等级是指将所述灰度值的取值范围分为5个区间,每个区间对应一个灰度等级。The N is 5, and the gray value of each pixel of the image ranges from 0 to 255, and the preset N gray levels refers to dividing the value range of the gray value into 5 intervals, each corresponding to a gray level.
可选地,Optionally,
所述判断模块还设置为将所述模糊图像删除。The determining module is further configured to delete the blurred image.
本发明实施例还提供一种计算机存储介质,所述计算机存储介质中存储有计算机可执行指令,所述计算机可执行指令用于执行上述方法。The embodiment of the invention further provides a computer storage medium, wherein the computer storage medium stores computer executable instructions, and the computer executable instructions are used to execute the above method.
上述方案对图像进行划分区域的预处理,并将预处理后的照片同预设条件进行比较来确定该照片是否为模糊图像,使终端具备了自动识别模糊图像的功能,避免了用户逐个筛选没有保存价值的模糊图像。同时,上述方案可将确定的模糊图像自动删除,避免了用户手动删除模糊图像,节省了用户的时间。The above solution preprocesses the divided area of the image, and compares the pre-processed photo with the preset condition to determine whether the photo is a blurred image, so that the terminal has the function of automatically recognizing the blurred image, thereby avoiding the user screening one by one. Save the blurred image of the value. At the same time, the above scheme can automatically delete the determined blurred image, thereby avoiding the user manually deleting the blurred image, thereby saving the user's time.
附图概述BRIEF abstract
图1为本发明实施例一种图像的处理方法的流程图;1 is a flowchart of a method for processing an image according to an embodiment of the present invention;
图2为本发明实施例中幼儿模式拍照处理方法的流程图;2 is a flowchart of a method for processing a child mode in an embodiment of the present invention;
图3为本发明实施例一种图像的处理装置的结构示意图。FIG. 3 is a schematic structural diagram of an image processing apparatus according to an embodiment of the present invention.
本发明的较佳实施方式Preferred embodiment of the invention
下文中将结合附图对本申请的实施例进行详细说明。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互任意组合。Embodiments of the present application will be described in detail below with reference to the accompanying drawings. It should be noted that, in the case of no conflict, the features in the embodiments and the embodiments in the present application may be arbitrarily combined with each other.
实施例一Embodiment 1
本发明实施例提供了一种图像的处理方法,如图1所示,所述方法包括:An embodiment of the present invention provides a method for processing an image. As shown in FIG. 1, the method includes:
步骤S11:获取图像每个像素点的灰度值,根据预设的N个灰度等级,将图像划分为一个或多个区域,同一区域中的每个像素点属于同一灰度等级,N为大于或者等于1的正整数;Step S11: Acquire a gray value of each pixel of the image, and divide the image into one or more regions according to the preset N gray levels, and each pixel in the same region belongs to the same gray level, where N is a positive integer greater than or equal to 1;
可选的,在进行区域划分时,将图像中属于同一个灰度等级且相邻的像素点划分为一个区域;图像的灰度等级的个数小于或者等于N。Optionally, when performing area division, pixels adjacent to the same gray level in the image and adjacent pixels are divided into one area; the number of gray levels of the image is less than or equal to N.
可以将N设置为5,设置5个灰度等级。图像每个像素点的灰度值的取值范围为0至255,预设的N个灰度等级是指将所述灰度值的取值范围分为5个区间,每个区间对应一个灰度等级。例如将图像的色彩量化灰度等级0-255转换为五个等级,将[0-255]划分为[0-50]、[51-100]、[101-150]、[151-200]以及[201-255]5个等级。将灰度等级一致的像素点连接成一个区域,图像被分成小于或者等于五个灰度等级的若干个区域,相同灰度等级的区域可以是多个。需要说明的是,也可以按照其它的划分规则设置灰度等级的个数,如将灰度等级的个数设置为6个、7个或者其它数量。You can set N to 5 and set 5 gray levels. The gray value of each pixel of the image ranges from 0 to 255. The preset N gray levels refer to dividing the value range of the gray value into five intervals, and each interval corresponds to one gray. Degree level. For example, the color quantization gradation level 0-255 of an image is converted into five levels, and [0-255] is divided into [0-50], [51-100], [101-150], [151-200], and [201-255] 5 levels. The pixels whose gray levels are uniform are connected into one area, and the image is divided into a plurality of areas smaller than or equal to five gray levels, and the area of the same gray level may be plural. It should be noted that the number of gray levels may be set according to other division rules, such as setting the number of gray levels to 6, 7, or other numbers.
步骤S12:计算图像划分的每个区域的面积,确定面积最大的区域,并计算图像的灰度等级的个数;Step S12: calculating the area of each area of the image division, determining the area with the largest area, and calculating the number of gray levels of the image;
步骤S13:根据面积最大的区域的面积和/或图像的灰度等级的个数判断图像是否为模糊图像。Step S13: It is determined whether the image is a blurred image according to the area of the area having the largest area and/or the number of gray levels of the image.
可选的,当面积最大的区域的面积与图像的全部面积的比值大于或等于第一阈值时,将图像作为模糊图像,或当面积最大的区域的面积与图像的全部面积的比值小于第一阈值且图像的灰度等级的个数小于或等于第二阈值时,将图像作为模糊图像。Optionally, when the ratio of the area of the area with the largest area to the total area of the image is greater than or equal to the first threshold, the image is regarded as a blurred image, or the ratio of the area of the area with the largest area to the total area of the image is smaller than the first When the threshold is used and the number of gradations of the image is less than or equal to the second threshold, the image is taken as a blurred image.
可以将第一阈值设置为80%,把第二阈值设置为2,也可以根据具体情况设置第一阈值和第二阈值。The first threshold may be set to 80%, the second threshold may be set to 2, and the first threshold and the second threshold may be set according to specific conditions.
可选地,Optionally,
将图像作为模糊图像后还包括:After the image is used as a blurred image, it also includes:
步骤S14:将模糊图像删除。Step S14: The blurred image is deleted.
可选的,在确定出模糊图像后,可以将该模糊图像直接自动删除,也可以不直接删除模糊图像,而是先将该模糊图像设置为待删除状态,待用户采用批量删除的方式处理。此外,还可以对已经成像的照片根据质量进行分类,把极其模糊的照片摘出来,然后可供用户一键删除。Optionally, after the fuzzy image is determined, the blurred image may be automatically deleted directly, or the blurred image may not be directly deleted, but the blurred image is first set to be deleted, and the user is processed by batch deletion. In addition, it is possible to sort the photos that have been imaged according to the quality, extract the extremely blurred photos, and then let the user delete them with one click.
在实际应用中,终端设备上可以设置有幼儿模式或者图像自动处理模式,用户可以通过启动幼儿模式或者图像自动处理模式来触发模糊图像的识别功能。In an actual application, the child device may be provided with a child mode or an image automatic processing mode, and the user may trigger the recognition function of the blurred image by starting the child mode or the image automatic processing mode.
下面结合附图和具体实施例对本发明的技术方案的实施作进一步的详细阐述。The implementation of the technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
图2描述了本发明实施例中幼儿模式拍照处理方法的总流程图。FIG. 2 depicts a general flow chart of a method for processing a child mode in the embodiment of the present invention.
步骤101:开启幼儿模式拍照。进入步骤102。Step 101: Turn on the toddler mode to take a photo. Go to step 102.
步骤102:预处理照片,将照片每个像素点的灰度值量化为0-255共256个灰度阶层。进入步骤103。Step 102: Preprocess the photo, and quantize the gray value of each pixel of the photo to 256 gray levels of 0-255. Go to step 103.
步骤103:将0-255分为五个等级,0-50为一级、51-100为二级、101-150为三级、151-200为四级、201-255为五级。进入步骤104。Step 103: Divide 0-255 into five levels, 0-50 is the first level, 51-100 is the second level, 101-150 is the third level, 151-200 is the fourth level, and 201-255 is the fourth level. Go to step 104.
步骤104:将灰度等级一致的像素点连接成一个区域,照片被分成小于等于五种灰度等级的若干个连通区域图片。进入步骤105。Step 104: Connect pixel points with the same gray level into one area, and the photo is divided into several connected area pictures of five or less gray levels. Go to step 105.
步骤105:计算每个灰度等级的连通区域面积。进入步骤106。Step 105: Calculate the area of the connected area of each gray level. Go to step 106.
步骤106:比较每个连通区域的面积值,选出最大的连通区域。进入步骤107。Step 106: Compare the area values of each connected area to select the largest connected area. Go to step 107.
步骤107:判断所有灰度等级的最大的连通区域是否大于整个照片面积的百分之八十,如果是则进入步骤109,如果连通区域小于或等于整个照片面积的百分之八十,进入步骤108。Step 107: Determine whether the maximum connected area of all gray levels is greater than 80% of the entire photo area. If yes, proceed to step 109. If the connected area is less than or equal to 80% of the entire photo area, proceed to the step. 108.
步骤108:判断这张照片的灰度等级个数是否少于或等于两个灰度等级,如果是则进入步骤109,如果这张照片的灰度等级个数大于两个灰度等级进入步骤110。Step 108: Determine whether the number of gray levels of the photo is less than or equal to two gray levels. If yes, proceed to step 109, if the number of gray levels of the photo is greater than two gray levels, proceed to step 110. .
步骤109:终端丢弃该照片,流程结束。Step 109: The terminal discards the photo, and the process ends.
步骤110:终端保存该照片,流程结束。Step 110: The terminal saves the photo, and the process ends.
本发明实施例的幼儿模式拍照状态下,终端对成像进行预判断处理,处理后的照片是否到达预设的模糊阀值,如果超过模糊阀值直接丢弃此次拍摄的照片,如果照片小于模糊阀值则保存。这样避免了用户逐个进行筛选那些没有保存价值的模糊照片。In the image mode of the infant mode of the embodiment of the present invention, the terminal performs pre-judgment processing on the image, and the processed photo reaches a preset fuzzy threshold. If the fuzzy threshold is exceeded, the photograph taken directly is discarded, if the photo is smaller than the fuzzy valve. The value is saved. This prevents the user from filtering out blurred photos that are not saved in value.
如图2所示,本发明实施例还提供一种图像的处理装置,所述装置包括:As shown in FIG. 2, an embodiment of the present invention further provides an image processing apparatus, where the apparatus includes:
预处理模块11,设置为获取图像每个像素点的灰度值,根据预设的N个灰度等级,将所述图像划分为一个或多个区域,同一区域中的每个像素点属于同一灰度等级,N为大于或者等于1的正整数;The pre-processing module 11 is configured to acquire a gray value of each pixel of the image, and divide the image into one or more regions according to the preset N gray levels, and each pixel in the same region belongs to the same Gray level, N is a positive integer greater than or equal to 1;
计算模块12,设置为计算所述图像划分的每个区域的面积,确定面积最大的区域;以及计算所述图像的灰度等级的个数;The calculating module 12 is configured to calculate an area of each area of the image division, determine an area with the largest area; and calculate a number of gray levels of the image;
判断模块13,设置为根据所述面积最大的区域的面积和/或所述图像的灰度等级的个数判断所述图像是否为模糊图像。The judging module 13 is configured to determine whether the image is a blurred image according to an area of the area having the largest area and/or a number of gradations of the image.
可选地,Optionally,
判断模块13设置为根据所述面积最大的区域的面积或所述图像的灰度等级的个数判断所述图像是否为模糊图像是指;The determining module 13 is configured to determine whether the image is a blurred image according to an area of the area with the largest area or a number of gray levels of the image;
当面积最大的区域的面积与所述图像的全部面积的比值大于或等于第一阈值时,将所述图像作为模糊图像;或面积最大的区域的面积与所述图像的全部面积的比值小于第一阈值且所述图像的灰度等级的个数小于或等于第二阈值时,将所述图像作为模糊图像。When the ratio of the area of the area with the largest area to the total area of the image is greater than or equal to the first threshold, the image is regarded as a blurred image; or the ratio of the area of the area having the largest area to the total area of the image is smaller than the first When the threshold is one and the number of gradations of the image is less than or equal to the second threshold, the image is taken as a blurred image.
可选地,Optionally,
将所述图像中属于同一个灰度等级且相邻的像素点划分为一个区域;所述图像的灰度等级的个数小于或者等于N;Subdividing pixel points belonging to the same gray level and adjacent pixels into one area; the number of gray levels of the image is less than or equal to N;
所述第一阈值为80%,所述第二阈值为2。The first threshold is 80% and the second threshold is 2.
可选地,Optionally,
所述N为5,所述图像每个像素点的灰度值的取值范围为0至255,所述预设的N个灰度等级是指将所述灰度值的取值范围分为5个区间,每个区间对应一个灰度等级。The N is 5, and the gray value of each pixel of the image ranges from 0 to 255, and the preset N gray levels refers to dividing the value range of the gray value into 5 intervals, each corresponding to a gray level.
可选地,Optionally,
所述判断模块13还设置为将所述模糊图像删除。The determining module 13 is further configured to delete the blurred image.
以上所述仅为本发明的优选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above description is only the preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes can be made to the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and scope of the present invention are intended to be included within the scope of the present invention.
本领域普通技术人员可以理解上述方法中的全部或部分步骤可通过程序来指令相关硬件完成,所述程序可以存储于计算机可读存储介质中,如只读存储器、磁盘或光盘等。可选地,上述实施例的全部或部分步骤也可以使用一个或多个集成电路来实现,相应地,上述实施例中的各模块/模块可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。本申请不限制于任何特定形式的硬件和软件的结合。One of ordinary skill in the art will appreciate that all or a portion of the steps described above can be accomplished by a program that instructs the associated hardware, such as a read-only memory, a magnetic or optical disk, and the like. Optionally, all or part of the steps of the foregoing embodiments may also be implemented by using one or more integrated circuits. Accordingly, each module/module in the foregoing embodiment may be implemented in the form of hardware, or may be implemented by using a software function module. Formal realization. This application is not limited to any specific combination of hardware and software.
工业实用性Industrial applicability上述技术方案使终端具备了自动识别模糊图像的功能,避免了用户逐个筛选没有保存价值的模糊图像。同时,上述方案可将确定的模糊图像自动删除,避免了用户手动删除模糊图像,节省了用户的时间。The above technical solution enables the terminal to automatically recognize the blurred image, thereby preventing the user from screening the blurred image without saving the value one by one. At the same time, the above scheme can automatically delete the determined blurred image, thereby avoiding the user manually deleting the blurred image, thereby saving the user's time.