Disclosure of Invention
The embodiment of the invention provides a moire removing method and device, which can accurately remove moire in a digital image.
In one aspect, an embodiment of the present invention provides a moire removing method, including:
judging whether the image to be processed has moire patterns;
if the image to be processed has moire fringes, converting the image to be processed into a frequency domain spectrogram;
filtering information with frequency higher than a preset threshold value in the spectrogram;
the filtered spectrogram is converted back to the time domain.
Optionally, the determining whether there is a moire pattern in the image to be processed includes:
acquiring a pixel corner result image of an image to be processed;
carrying out regional statistics on corner statistical values in a corner result graph;
if the ratio of the number of the regions with the region corner statistical value exceeding the preset region corner statistical threshold value to the total number of the regions exceeds a preset proportion, determining that Moire exists in the image to be processed; otherwise, determining that no moire exists in the image to be processed.
Optionally, the pixel corner point is a pixel point having a difference with both the left neighbor and the upper neighbor.
Optionally, converting the image to be processed into a frequency-domain spectrogram comprises:
down-sampling an image to be processed, and converting the down-sampled image into a frequency spectrum graph of a frequency domain;
after converting the filtered spectrogram back to the time domain, the method further comprises the following steps:
the image converted back to the time domain is up-sampled.
In another aspect, an embodiment of the present invention provides a moire removing device, including:
the judging module is used for judging whether the image to be processed has Moire patterns;
the first conversion module is used for converting the image to be processed into a frequency spectrum graph of a frequency domain when Moire lines exist in the image;
the filtering module is used for filtering information with the frequency higher than a preset threshold value in the spectrogram;
and the second conversion module is used for converting the filtered spectrogram back to a time domain.
Optionally, the determining module includes:
the acquisition submodule is used for acquiring a pixel corner result image of the image to be processed;
the statistic submodule is used for carrying out regional statistic on the corner statistic value in the corner result graph;
the determining submodule is used for determining that Moire patterns exist in the image to be processed when the ratio of the number of the regions with the region corner statistical value exceeding the preset region corner statistical threshold value to the total number of the regions exceeds a preset proportion; otherwise, determining that no moire exists in the image to be processed.
Optionally, the pixel corner point is a pixel point having a difference with both the left neighbor and the upper neighbor.
Optionally, the first conversion module is further configured to down-sample the image to be processed, and convert the down-sampled image into a frequency spectrogram of a frequency domain;
the second conversion module is further configured to convert the filtered spectrogram back to the time domain and then perform upsampling processing on the image converted back to the time domain.
According to the method and the device for removing the moire fringes, whether the moire fringes exist in the image to be processed is judged, when the moire fringes exist in the image to be processed, the image to be processed is converted into a frequency domain spectrogram, high-frequency information in the frequency domain spectrogram is filtered, and the filtered spectrogram is converted back to a time domain, so that the image with the moire fringes removed can be obtained. According to the technical scheme provided by the embodiment of the invention, whether the moire fringes exist in the image to be processed is judged, so that the removal of the moire fringes is more accurate.
Detailed Description
According to the method and the device for removing the moire fringes, provided by the embodiment of the invention, whether the moire fringes exist in the image to be processed is judged, and the moire fringes are removed aiming at the image with the moire fringes, so that the removal of the moire fringes is more accurate. The following detailed description of embodiments and implementations of the invention is provided with reference to the accompanying drawings.
Referring to fig. 1, an embodiment of the present invention provides a moire removal method, which includes steps 101 to 104.
Step 101: judging whether the image to be processed has moire fringes or not, and if yes, entering step 102; otherwise, the method is ended.
Step 102: and converting the image to be processed into a frequency spectrum diagram of a frequency domain.
Step 103: and filtering information with the frequency higher than a preset threshold value in the spectrogram.
A time domain image can be transformed into a spectrogram through a frequency domain, and information is lossless. Moire in the time domain image generally corresponds to high frequency information in a frequency spectrum image of a frequency domain, and if the image has moire, the moire in the time domain image can be removed by filtering the high frequency information.
In an embodiment of the present invention, the preset threshold may be determined according to a highest frequency in a spectrogram, for example, the preset threshold may be a highest frequency f in the spectrogram of a frequency domainmax70% of (1), i.e. filtering out excess frequenciesThe ratio exceeds fmax70% of the information. In practical application, the preset threshold may be set in combination with a frequency spectrogram of a frequency domain, which is not limited in this application as long as information of a high-frequency region can be filtered out.
Step 104: the filtered spectrogram is converted back to the time domain.
And converting the filtered spectrogram back to a time domain to obtain a moire-removed time domain image.
As described in the background art, when a screen of a television or a computer is photographed by an electronic device such as a digital camera or a mobile phone or a texture having a microgroove in a photographed object, an image having a moire pattern is easily generated. Sometimes, there are no moire in the image, and only a lot of details are available, and both moire and details in the time domain image correspond to high frequency information in the frequency domain spectrogram, and if the high frequency information of the frequency domain spectrogram is filtered in the frequency domain without distinction in order to remove moire, the details of the time domain image without moire become blurred.
According to the technical scheme provided by the embodiment of the invention, whether the moire fringes exist in the image to be processed is judged before the image to be processed is processed, and the moire fringes in the image to be processed are removed by filtering information with the frequency higher than a preset threshold value in a spectrogram only when the moire fringes really exist in the image to be processed, so that the removal of the moire fringes is more accurate.
Referring to fig. 2, in an embodiment of the present invention, determining whether there is a moire pattern in the image to be processed may include steps 1011 to 1013.
Step 1011: and acquiring a pixel corner result image of the image to be processed.
The pixel corner result map needs to be obtained by scanning the binarized image.
If the image to be processed is a non-binary image, the image to be processed can be binarized firstly, and then the pixel corner points of the binarized image to be processed are scanned to obtain a pixel corner point result image of the image.
Image binarization is the most common and important processing means in image analysis and processing, and the number of binary processing methods is very large. The present application does not limit the specific binarization method. Fig. 3-1 is a schematic diagram of an image to be processed according to an embodiment of the present invention, which is a non-binarized image, and fig. 3-2 is a binarized image corresponding to fig. 3-1.
If the image to be processed is a binarized image, for example, if fig. 3-2 is the image to be processed, then the pixel corners in the image to be processed may be directly processed to obtain a pixel corner result graph.
In the embodiment of the invention, the pixel corner points are pixel points which are different from the left neighbor and the upper neighbor. That is, if there is a difference between a certain pixel and its left neighbor and its upper forest, its pixel value is set to 255 (white), otherwise its pixel value is set to 0 (black). Fig. 4 is a schematic diagram of a pixel corner result graph according to an embodiment of the present invention.
Step 1013: and carrying out regional corner statistical value in the pixel corner result image by regions.
Fig. 5 is a partial schematic diagram of a regional corner statistical value in a regional statistical pixel corner result graph according to an embodiment of the present invention. In the embodiment of the invention, the pixel corner result image is divided into a plurality of areas, and the number of corners in each area is the statistical value of the corners of the area. Step 1014: if the ratio of the number of the regions with the region corner statistical value exceeding the preset region corner statistical threshold value to the total number of the regions exceeds a preset proportion, determining that Moire exists in the image to be processed; otherwise, determining that no moire exists in the image to be processed.
The corner points in the corner points map of the moire-free image may be much fewer than the corner points of the moire-containing image, since the moire itself may create many corner points. Based on this, in the embodiment of the present invention, each statistical value of the area corner points obtained through statistics is compared with the statistical threshold of the area corner points and recorded, if the ratio of the number of the areas, in which the statistical value of the area corner points exceeds the statistical threshold of the preset area corner points, to the total number of the areas exceeds a preset ratio, for example, if the ratio exceeds 60%, it is indicated that there are very many corner points in the image, it is determined that there are moire patterns in the corresponding image to be processed, otherwise there are no moire patterns in the corresponding image to be processed.
The region corner point statistical threshold is a preset threshold of the number of corner points in the region, and both the region corner point statistical threshold and the preset proportion can be determined according to actual conditions, which is not limited by the invention.
In an embodiment of the invention, whether the image to be processed has moire or not can be judged through the corner result image through various classification algorithms.
For example, in one embodiment, a gradient boosting decision tree may be employed(Gradient Boosting DecisionTree,GBDT)To make a judgment. And taking the statistical values of all the areas as all the dimensions of the decision tree, and starting from the top point to judge whether all the dimensions are larger than a preset threshold value. If all the nodes or the nodes exceeding the preset percentage result in being larger than the preset threshold value, the moire in the image to be processed corresponding to the corner result graph can be determined.
After determining that the moire is present in the image to be processed, the image to be processed may be processed according to the steps 102 and 104 shown in fig. 1 to remove the moire.
Fig. 6 is an image of the image of fig. 3-2 after moire removal in accordance with a method provided by an embodiment of the present invention. Compared with the image shown in the figure 3-2, the image with the moire fringes removed is clearer, and the subsequent processing of the image is facilitated.
Referring to fig. 7, an embodiment of the present invention provides a moire removing method, including steps 701 to 706.
Step 701: judging whether the image to be processed has moire fringes or not, if so, executing a step 702; otherwise, the method is ended.
Step 702: and performing down-sampling on the image to be processed.
Step 703: and converting the down-sampled image into a frequency domain spectrogram.
Down-sampling is the process of reducing the sampling rate of a particular signal, and embodiments of the present invention reduce the data size by down-sampling. The down-sampling factor (often denoted by the symbol M) is typically an integer or rational number greater than 1. This factor expresses the sampling period becoming several times as large. Since the down-sampling reduces the data size, the conversion efficiency can be greatly improved by converting the down-sampled image from the time domain to the frequency domain.
Step 704: and filtering information with the frequency higher than a preset threshold value in the spectrogram.
Step 705: the filtered spectrogram is converted back to the time domain.
Step 706: the image converted back to the time domain is up-sampled.
Since the image to be processed is down-sampled before, after the moire in the image is removed in the frequency domain, the image converted back to the time domain needs to be up-sampled to restore the image. The corresponding upsampling factor may be set with reference to the previous downsampling factor. For example, if the previous down-sampling period is M times the original sampling period, the corresponding up-sampling period is 1/M of the original sampling period, and thus the image can be restored.
According to the moire removing method provided by the embodiment of the invention, after the moire in the image to be processed is determined, the image to be processed is further subjected to down sampling, the image to be sampled is subjected to frequency domain transformation, then high-frequency information in the image is filtered to remove the moire, and then the image is converted back to the time domain to be subjected to up sampling, so that the image with the moire removed is obtained.
In correspondence with the moire removing method, the present application also provides a moire removing device, and referring to fig. 8, an embodiment of the present invention provides a moire removing device including:
a judging module 801, configured to judge whether there is moire in the image to be processed;
a first conversion module 802, configured to convert the image to be processed into a frequency spectrogram of a frequency domain when there are moire fringes in the image;
a filtering module 802, configured to filter information in a spectrogram, where a frequency is higher than a preset threshold;
a second conversion module 804, configured to convert the filtered spectrogram back to the time domain.
In this embodiment, only the embodiment of the apparatus is briefly described, and reference may be made to the embodiment of the moire removing method described above in relevant places.
According to the moire removing device provided by the embodiment of the invention, before the image to be processed is processed, whether moire exists in the image to be processed is judged, and only when the moire really exists in the image to be processed is determined, the moire in the image to be processed is removed by filtering the information of which the frequency in the spectrogram is higher than the preset threshold value, so that the removal of the moire is more accurate.
Optionally, referring to fig. 9, in an embodiment of the present invention, the determining module 801 includes:
an acquiring word module 8011 configured to acquire a pixel corner result image of the image to be processed;
the statistic submodule 8012 is configured to perform regional statistic on corner statistic values in the corner result map;
a determining submodule 8013, configured to determine that, in the area of the binarized image, the ratio of the number of areas in which the corner point statistic value exceeds the preset area corner point statistic threshold value to the total number of the areas exceeds the preset ratio, and that a moir é exists in the image to be processed; otherwise, determining that no moire exists in the image to be processed.
When the moire in the image to be processed is determined, the moire removing device can continue to process the image to be processed to remove the moire in the image to be processed.
Optionally, in an embodiment of the present invention, the first conversion module 802 is further configured to perform downsampling on the image to be processed, and convert the downsampled image into a frequency spectrogram of a frequency domain;
the second conversion module 804 is further configured to convert the filtered spectrogram back to the time domain, and then perform upsampling processing on the image converted back to the time domain.
According to the moire removing device provided by the embodiment of the invention, after the moire in the image to be processed is determined, the image to be processed is further subjected to down sampling, the image to be sampled is subjected to frequency domain transformation, high-frequency information in the image is filtered to remove the moire, and then the image is converted back to the time domain to be subjected to up sampling, so that the image with the moire removed is obtained.
Fig. 10 is a schematic diagram of a hardware structure of an electronic device for performing a moire removing method according to an embodiment of the present application, where as shown in fig. 10, the electronic device includes:
one or more processors 1010 and a memory 1020, one processor 1010 being illustrated in fig. 10.
The apparatus performing the data storage method may further include: an input device 1030 and an output device 1040.
The processor 1010, memory 1020, input device 1030, and output device 1040 may be connected by a bus or other means, such as bus 1050 in fig. 10.
The memory 1020, which is a non-volatile computer-readable storage medium, may be used for storing non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions/modules (e.g., the respective modules shown in fig. 8) corresponding to the data storage method in the embodiment of the present application. The processor 1010 executes various functional applications of the server and data processing by executing nonvolatile software programs, instructions, and modules stored in the memory 1020, that is, implements the data storage method of the above-described method embodiment.
The memory 1020 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function; the storage data area may store data created according to use of the data storage device, and the like. Further, the memory 1020 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some embodiments, memory 1020 may optionally include memory located remotely from processor 1010, which may be connected to a data storage device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 1030 may receive input numeric or character information and generate key signal inputs related to user settings and function control of the data storage device. Output device 1040 may include a display device such as a display screen.
The one or more modules are stored in the memory 1020 and, when executed by the one or more processors 1010, perform the data storage method of any of the method embodiments described above.
The product can execute the method provided by the embodiment of the application, and has the corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the methods provided in the embodiments of the present application.
The electronic device of embodiments of the present invention exists in a variety of forms, including but not limited to:
(1) a mobile communication device: such devices are characterized by mobile communications capabilities and are primarily targeted at providing voice, data communications. Such terminals include smart phones, multimedia phones, functional phones, and low-end phones, among others.
(2) Ultra mobile personal computer device: the equipment belongs to the category of personal computers, has calculation and processing functions and generally has the characteristic of mobile internet access. Such terminals include: a PDA (Personal digital assistant), a Mobile Internet Device (MID, Mobile Internet Device), and an Ultra-Mobile Personal Computer (UMPC) Device, etc.
(3) Portable entertainment devices such devices may display and play multimedia content. The devices comprise audio and video players, handheld game consoles, electronic books, intelligent toys and portable vehicle-mounted navigation devices.
(4) A server: the device for providing the computing service comprises a processor, a hard disk, a memory, a system bus and the like, and the server is similar to a general computer architecture, but has higher requirements on processing capacity, stability, reliability, safety, expandability, manageability and the like because of the need of providing high-reliability service.
(5) And other electronic devices with data interaction functions.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. For example, the above-described embodiments of moire removal device are merely illustrative, and for example, the division of the modules is merely a logical division, and there may be other divisions when actually implemented, for example, a plurality of modules or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication link may be through some interfaces, and the indirect coupling or communication link of the modules may be in an electrical, mechanical or other form.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing module, or each of the modules may exist alone physically, or two or more modules are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode.
The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It should be noted that, for the sake of simplicity, the above-mentioned method embodiments are described as a series of acts or combinations, but those skilled in the art should understand that the present invention is not limited by the described order of acts, as some steps may be performed in other orders or simultaneously according to the present invention. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no acts or modules are necessarily required of the invention.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
The preferred embodiments of the invention disclosed above are intended to be illustrative only. Alternative embodiments are not exhaustive and do not limit the invention to the precise embodiments described. Obviously, many modifications and variations are possible in light of the above teaching. The embodiments were chosen and described in order to best explain the principles of the invention and the practical application, to thereby enable others skilled in the art to best utilize the invention. The invention is limited only by the claims and their full scope and equivalents.