Image processing method, apparatus, device, and storage medium
By calculating the vertical and horizontal discrete values of the image to determine the cropping boundary, the problem of long image cropping processing time in the existing technology is solved, and fast and efficient image cropping is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-20
- Publication Date
- 2026-03-17
AI Technical Summary
Existing technologies for image cropping have long processing times, resulting in low processing efficiency. Manual cropping is slow and complex algorithms require long computation times.
By calculating the vertical and horizontal discrete values of each pixel in the image, the vertical and horizontal cropping boundaries are determined, and the image is cropped based on these boundaries, simplifying the calculation method to one that does not require complex algorithms.
It achieves fast image cropping, reduces computation time, improves processing efficiency, and avoids the drawbacks of manual processing and complex calculations.
Smart Images

Figure CN115797368B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to an image processing method, apparatus, device, and storage medium. Background Technology
[0002] Image edges are prevalent in scanned documents, ID photos, and intentionally collaged images. These invalid edges waste storage resources and also negatively impact subsequent recognition algorithms. Therefore, cropping image edges to obtain more targeted information is an important challenge. Existing technologies employ two methods: one is based on human experience, but this method is time-consuming in determining boundaries, resulting in slow and inefficient manual image cropping; the other method uses complex edge detection operators to determine cropping boundaries, but the complex algorithms used in this approach lead to long computation times, reducing image cropping efficiency. Summary of the Invention
[0003] This disclosure provides an image processing method, apparatus, device, and storage medium to address the shortcomings of existing technologies where image cropping processes are time-consuming and thus reduce processing efficiency, thereby enabling rapid image cropping.
[0004] This disclosure provides an image processing method, comprising: acquiring an image to be processed; acquiring the pixel value of each pixel in the image to be processed; calculating, based on the pixel value, a vertical discrete value corresponding to at least one column of the pixels in the image to be processed, and calculating a horizontal discrete value corresponding to at least one row of the pixels in the image to be processed; determining, based on the vertical discrete value, a vertical cropping boundary of the image to be processed, and determining, based on the horizontal discrete value, a horizontal cropping boundary of the image to be processed; and cropping the image based on the vertical cropping boundary and the horizontal cropping boundary to obtain a processed image.
[0005] According to an image processing method provided in this disclosure, the step of calculating the vertical discrete value corresponding to at least one column of pixels in the image to be processed includes: determining at least one column of first pixels to be processed in the image to be processed at intervals of a first preset number of pixels in the horizontal direction of the image to be processed; and calculating the vertical discrete value corresponding to each column of the first pixels to be processed. The step of calculating the horizontal discrete value corresponding to at least one row of pixels in the image to be processed includes: determining at least one row of second pixels to be processed in the image to be processed at intervals of a second preset number of pixels in the vertical direction of the image to be processed; and calculating the horizontal discrete value corresponding to each row of the second pixels to be processed.
[0006] According to an image processing method provided in this disclosure, the step of calculating the vertical discrete values corresponding to at least one column of pixels in the image to be processed includes: determining the pixel values corresponding to at least one column of pixels in the image to be processed; calculating the variance of the pixel values column by column, and using the variance of each column as the vertical discrete value corresponding to each column of pixels; the step of calculating the horizontal discrete values corresponding to at least one row of pixels in the image to be processed includes: determining the pixel values corresponding to at least one row of pixels in the image to be processed; calculating the variance of the pixel values row by row, and using the variance of each row as the horizontal discrete value corresponding to each row of pixels.
[0007] According to an image processing method provided in this disclosure, the vertical cropping boundary includes a left cropping boundary and a right cropping boundary, and the horizontal cropping boundary includes an upper cropping boundary and a lower cropping boundary; determining the vertical cropping boundary of the image to be processed based on the vertical discrete value includes: determining a first vertical discrete value, wherein the first vertical discrete value is the vertical discrete value that first appears from the left and is greater than a vertical discrete threshold; taking the pixel column corresponding to the first vertical discrete value as the left cropping boundary; determining a second vertical discrete value, wherein the second vertical discrete value is the vertical discrete value that first appears from the right and is greater than the vertical discrete threshold. Discrete values; the pixel column corresponding to the second vertical discrete value is used as the right cropping boundary; determining the horizontal cropping boundary of the image to be processed based on the horizontal discrete value includes: determining a third horizontal discrete value, wherein the third horizontal discrete value is the first horizontal discrete value that is greater than the horizontal discrete threshold from the top; using the pixel row corresponding to the third horizontal discrete value as the upper cropping boundary; determining a fourth horizontal discrete value, wherein the fourth horizontal discrete value is the first horizontal discrete value that is greater than the horizontal discrete threshold from the bottom; using the pixel row corresponding to the fourth horizontal discrete value as the lower cropping boundary.
[0008] According to an image processing method provided in this disclosure, before determining at least one column of first pixels to be processed in the image to be processed at intervals of a first preset number of pixels in the horizontal direction, the method further includes: obtaining a preset number of pixel samples; obtaining the total number of columns of pixels in the image to be processed; calculating the total number of columns divided by the number of pixel samples to obtain a first integer quotient; obtaining the total number of rows of pixels in the image to be processed; calculating the total number of rows divided by the number of pixel samples to obtain a second integer quotient; using the first integer quotient as the first preset number of pixels and the second integer quotient as the second preset number of pixels; or, determining the maximum value between the first integer quotient and the second integer quotient, and using the maximum value as the first preset number of pixels and the second preset number of pixels, respectively.
[0009] According to an image processing method provided in this disclosure, the step of obtaining the image to be processed includes: obtaining an original image; performing grayscale processing on the original image to obtain the image to be processed; the step of obtaining the pixel value of each pixel in the image to be processed includes: obtaining the pixel value of each pixel based on the grayscale value of each pixel in the image to be processed.
[0010] According to an image processing method provided in this disclosure, the step of cropping an image based on the vertical cropping boundary and the horizontal cropping boundary to obtain a processed image includes: restoring the vertical cropping boundary and the horizontal cropping boundary in the image to be processed to at least one original cropping boundary in the original image; and cropping the original image based on the original cropping boundary to obtain the processed image.
[0011] This disclosure also provides an image processing apparatus, comprising: an image acquisition module for acquiring an image to be processed; a pixel value acquisition module for acquiring the pixel value of each pixel in the image to be processed; a calculation module for calculating, based on the pixel values, vertical discrete values corresponding to at least one column of pixels in the image to be processed, and horizontal discrete values corresponding to at least one row of pixels in the image to be processed; a boundary determination module for determining, based on the vertical discrete values, a vertical cropping boundary of the image to be processed, and a horizontal cropping boundary of the image to be processed, based on the horizontal discrete values; and a cropping module for cropping the image to be processed based on the vertical cropping boundary and the horizontal cropping boundary to obtain a processed image.
[0012] This disclosure also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the image processing method as described above.
[0013] This disclosure also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the image processing method as described above.
[0014] The image processing method, apparatus, device, and storage medium disclosed herein acquire an image to be processed, and calculates vertical discrete values for at least one column and horizontal discrete values for at least one row of the image based on the pixel value of each pixel in the image. Then, vertical and horizontal cropping boundaries are determined using the vertical and horizontal discrete values, respectively. Image cropping is performed based on the vertical and horizontal cropping boundaries to obtain the processed image. In this process, the pixel value of each pixel in the image to be processed is calculated, and the vertical and horizontal cropping boundaries are determined based on the calculated vertical and horizontal discrete values. The calculation method is simple, requiring no complex processing algorithms, eliminating the need for manual processing, and avoiding the huge computational load caused by complex calculations. This reduces the time spent on image cropping processing, improves the efficiency of image cropping processing, and enables rapid image cropping processing. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in this disclosure or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a flowchart illustrating the image processing method provided in this disclosure;
[0017] Figure 2 These are example images provided in this publication;
[0018] Figure 3 This is an example image of image cropping provided in this publication;
[0019] Figure 4 This is a schematic diagram of the structure of the image processing apparatus provided in this disclosure;
[0020] Figure 5 This is a schematic diagram of the structure of the electronic device provided in this disclosure. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the protection scope of the embodiments of this disclosure.
[0022] The image processing method disclosed herein is intended for image cropping. This method can be automated using a computer program that can be implemented in any device with data processing capabilities, such as a server, smartphone, laptop, or any other device capable of data processing. The scope of protection of this disclosure is not limited to the device implementing this method. The following describes the method in conjunction with... Figures 1-3 The image processing methods provided in the various embodiments of this disclosure are described.
[0023] In one embodiment, such as Figure 1 As shown, the process of implementing the image processing method is as follows:
[0024] Step 101: Obtain the image to be processed.
[0025] In this embodiment, the image to be processed refers to the image that needs to be cropped.
[0026] In one embodiment, the image to be processed is the preprocessed version of the original image. The original image can be obtained from a folder, the network, or directly captured by an image acquisition device such as a camera. The acquired original image is often a color image. When calculating pixel values, for a grayscale image, the pixel value is its grayscale value; for a color image, the grayscale value needs to be obtained through a function mapping to obtain the pixel value. Therefore, after obtaining the original image, preprocessing requires converting it to grayscale to facilitate subsequent calculations. Specifically, obtaining the image to be processed includes: obtaining the original image; and converting the original image to grayscale to obtain the image to be processed.
[0027] In this embodiment, to further reduce computational load, the preprocessing of the original image, in addition to grayscale conversion, may also include filtering and scaling processes. The filtering process can be any one of median filtering, mean filtering, and Gaussian filtering. The scaling process can scale the resolution of the original image to a preset resolution; for example, scaling an original image with a resolution of 1280*720 to a 320*240 image to be processed.
[0028] More specifically, preprocessing can be configured with specific steps and procedures based on actual conditions and needs. For example, the original image can be converted to grayscale only to obtain the image to be processed; or, the original image can be scaled to a preset resolution first, and then the scaled image can be converted to grayscale to obtain the image to be processed; or, the original image can be converted to grayscale first, and then the grayscale image can be scaled to a preset resolution to obtain the image to be processed; or, the original image can be first subjected to median filtering, then the filtered image can be scaled, and finally the scaled image can be converted to grayscale to obtain the image to be processed.
[0029] In this embodiment, filtering removes noise from the original image, improving the accuracy of post-processing; scaling reduces the resolution of the original image to a preset resolution, facilitating subsequent pixel processing; and grayscale conversion converts a color image to grayscale, reducing the computational load for subsequent pixel value calculations. By performing preprocessing steps such as filtering, scaling, and / or grayscale conversion on the original image, a more uniform format of the image to be processed is obtained, facilitating subsequent pixel value calculations, further accelerating image processing speed, and improving the efficiency of image cropping.
[0030] Step 102: Obtain the pixel value of each pixel in the image to be processed.
[0031] In this embodiment, after obtaining the image to be processed, the image is parsed to obtain the pixel value of each pixel in the image to be processed.
[0032] In one embodiment, if the image to be processed is obtained by grayscale processing of the original image, the pixel value of each pixel in the image to be processed is obtained. The process is as follows: the pixel value of each pixel is obtained based on the grayscale value of each pixel in the image to be processed.
[0033] Step 103: Based on the pixel values, calculate the vertical discrete values corresponding to at least one column of pixels in the image to be processed, and calculate the horizontal discrete values corresponding to at least one row of pixels in the image to be processed.
[0034] In this embodiment, the pixels of the image to be processed are arranged in row and column order, such as... Figure 2 The image shown is an example image to be processed after scaling and grayscale conversion. The image resolution is 320*240, meaning the width (horizontal) of the image to be processed is 320 pixels and the height (vertical) is 240 pixels. In this image, each column consists of 240 pixels, and each row consists of 320 pixels.
[0035] In one embodiment, the vertical discrete value corresponding to each row of pixels in the image to be processed can be calculated, and the horizontal discrete value corresponding to each column of pixels in the image to be processed can be calculated. The vertical discrete value characterizes the degree of dispersion of pixel values corresponding to a column of pixels; the horizontal discrete value characterizes the degree of dispersion of pixel values corresponding to a row of pixels. The discrete value can be any pre-defined numerical value that can represent the degree of dispersion, such as the range, interquartile range, variance, standard deviation, or coefficient of variation of pixel values.
[0036] In one embodiment, taking the variance as an example, the vertical discrete values corresponding to at least one column of pixels in the image to be processed are calculated. The specific implementation process is as follows: determine the pixel values corresponding to at least one column of pixels in the image to be processed; calculate the variance of the pixel values column by column, and use the variance of each column as the vertical discrete value corresponding to each column of pixels. The horizontal discrete values corresponding to at least one row of pixels in the image to be processed are calculated. The specific implementation process is as follows: determine the pixel values corresponding to at least one row of pixels in the image to be processed; calculate the variance of the pixel values row by row, and use the variance of each row as the horizontal discrete value corresponding to each row of pixels.
[0037] In this embodiment, Figure 2 Taking the image shown as an example, the image to be processed includes 320 columns of pixels vertically, with each column containing 240 pixels. By calculating the variance of the pixel values corresponding to each column, we can obtain 320 discrete vertical values corresponding to each of the 320 columns of pixels. Similarly, the image to be processed includes 240 rows of pixels horizontally, with each row containing 320 pixels. By calculating the variance of the pixel values corresponding to each row, we can obtain 240 discrete horizontal values corresponding to each of the 240 rows of pixels.
[0038] More specifically, Figure 2 The dashed line represents the first column of pixels in the vertical direction. Taking the first column of pixels as an example, the corresponding variance is calculated according to the following formula (1):
[0039]
[0040] Among them, s 2 Let x represent the variance, where x is the average of the 240 pixels in the first column. i This represents the pixel value of any pixel in the first column of pixels, and n represents the number of pixels in the first column of pixels. That is, when calculating the variance of the first column of pixels, n = 240.
[0041] In this embodiment, the variance of the pixels in other rows or columns is calculated using the above formula (1).
[0042] In this embodiment, the process of directly calculating pixel values is logically simple, easy to implement in a programmed manner, reduces image processing time, and improves image cropping efficiency.
[0043] In one embodiment, to further accelerate the calculation process and reduce calculation time, interval calculation is performed. Specifically, the vertical discrete values corresponding to at least one column of pixels in the image to be processed are calculated as follows: At least one column of first pixels to be processed is determined in the horizontal direction of the image to be processed at intervals of a first preset number of pixels; the vertical discrete value corresponding to each column of first pixels to be processed is calculated. The horizontal discrete values corresponding to at least one row of pixels in the image to be processed are calculated as follows: At least one row of second pixels to be processed is determined in the vertical direction of the image to be processed at intervals of a second preset number of pixels; the horizontal discrete value corresponding to each row of second pixels to be processed is calculated.
[0044] In this embodiment, instead of calculating each row and column of pixels in the image to be processed, at least one column of first pixels to be processed and at least one row of second pixels to be processed are selected intermittently.
[0045] Specifically, with Figure 2 Taking the image shown as an example, each row in the horizontal direction has 320 pixels, and each column in the vertical direction has 240 pixels. When the first preset pixel count is 8, then in the horizontal direction, every 8 columns of pixels are used to determine a first column of pixels to be processed, for a total of 40 columns of pixels. The method provided in the above embodiment is used to calculate 40 vertical discrete values corresponding to each of these 40 columns of pixels. When the second preset pixel count is 6, then in the vertical direction, every 6 rows of pixels are used to determine a second row of pixels to be processed, for a total of 40 rows of pixels. The method provided in the above embodiment is used to calculate 40 horizontal discrete values corresponding to each of these 40 rows of pixels. Then, image cropping is performed based on the 40 vertical and 40 horizontal discrete values.
[0046] In one embodiment, the first preset number of pixels and the second preset number of pixels can be set in any suitable way according to the actual situation and needs. The scope of protection of this disclosure is not limited to the specific values of the first preset number of pixels and the second preset number of pixels.
[0047] In one approach, the first and second preset pixel counts can be manually set to fixed values based on experience and / or experimental data. The first and second preset pixel counts can be the same or different. When processing different images, a fixed first and second preset pixel count is used to accelerate computation.
[0048] In another approach, the first and second preset pixel counts are dynamically determined based on the pixel counts of the width and height of the image to be processed and a pre-set pixel sampling number. Specifically, before determining at least one column of pixels to be processed in the image to be processed at intervals of the first preset pixel count in the horizontal direction, a preset pixel sampling number is obtained; the total number of columns of pixels in the image to be processed is obtained; the total number of columns is divided by the pixel sampling number to obtain a first integer quotient; the total number of rows of pixels in the image to be processed is obtained; the total number of rows is divided by the pixel sampling number to obtain a second integer quotient; the first integer quotient is used as the first preset pixel count, and the second integer quotient is used as the second preset pixel count; or, the maximum value of the first and second integer quotients is determined, and the maximum value is used as the first and second preset pixel counts, respectively.
[0049] In this method, the values of the first preset pixel count and the second preset pixel count can be the same or different. When the first integer quotient is used as the first preset pixel count and the second integer quotient is used as the second preset pixel count, the values of the first preset pixel count and the second preset pixel count are different; when the maximum value of the first integer quotient and the second integer quotient is determined, and the maximum value is used as the first preset pixel count and the second preset pixel count respectively, the values of the first preset pixel count and the second preset pixel count are the same.
[0050] More specifically, with Figure 2 Taking the image shown as an example, the image to be processed has 320 pixels per row horizontally and 240 pixels per column vertically. The preset pixel sampling number is 40, so 320 / 40 = 8 pixels horizontally and 240 / 40 = 6 pixels vertically. When the first preset pixel count and the second preset pixel count are different, the first preset pixel count = 8 and the second preset pixel count = 6. When the first preset pixel count and the second preset pixel count are the same, the maximum value of 8 and 6 can be determined, i.e., max(8, 6) = 8, then the first preset pixel count = the second preset pixel count = 8.
[0051] In this example, the first preset number of pixels and the second preset number of pixels are set to fixed values, which can further reduce the amount of calculation in the implementation process of this method and speed up the calculation. The first preset number of pixels and the second preset number of pixels are dynamically set according to the number of pixel samples, which can make the first preset number of pixels and the second preset number of pixels more suitable for the image to be processed, and improve the accuracy of image cropping.
[0052] Step 104: Determine the vertical cropping boundary of the image to be processed based on the vertical discrete values, and determine the horizontal cropping boundary of the image to be processed based on the horizontal discrete values.
[0053] In this embodiment, after calculating the vertical and horizontal discrete values, the cropping boundary of the image to be processed can be determined based on the degree of dispersion of the pixel values in each column and each row.
[0054] In one embodiment, the vertical clipping boundaries include a left clipping boundary and a right clipping boundary, and the horizontal clipping boundaries include an upper clipping boundary and a lower clipping boundary. With these four clipping boundaries (left, right, upper, and lower), not only symmetrical clipping of each edge can be achieved, but also asymmetrical clipping of each edge can be realized.
[0055] Specifically, based on vertical discrete values, the vertical cropping boundaries of the image to be processed are determined as follows: A first vertical discrete value is determined, where the first vertical discrete value is the first vertical discrete value from the left that is greater than a vertical discrete threshold; the pixel column corresponding to the first vertical discrete value is used as the left cropping boundary; a second vertical discrete value is determined, where the second vertical discrete value is the first vertical discrete value from the right that is greater than a vertical discrete threshold; the pixel column corresponding to the second vertical discrete value is used as the right cropping boundary. Based on horizontal discrete values, the horizontal cropping boundaries of the image to be processed are determined as follows: A third horizontal discrete value is determined, where the third horizontal discrete value is the first horizontal discrete value from the top that is greater than a horizontal discrete threshold; the pixel row corresponding to the third horizontal discrete value is used as the upper cropping boundary; a fourth horizontal discrete value is determined, where the fourth horizontal discrete value is the first horizontal discrete value from the bottom that is greater than a horizontal discrete threshold; the pixel row corresponding to the fourth horizontal discrete value is used as the lower cropping boundary.
[0056] In this embodiment, starting from the vertical discrete value corresponding to the leftmost column of pixels in the horizontal direction in the image to be processed, each value is compared with the vertical discrete threshold. When a vertical discrete value greater than the vertical discrete threshold appears for the first time, the first vertical discrete value greater than the threshold from the left is determined as the first vertical discrete value; the pixel column corresponding to the first vertical discrete value is used as the left cropping boundary.
[0057] Starting from the rightmost column of pixels in the horizontal direction of the image to be processed, each vertical discrete value is compared with the vertical discrete threshold. When a vertical discrete value greater than the threshold appears for the first time, the first vertical discrete value greater than the threshold from the right is determined as the second vertical discrete value. The column of pixels corresponding to the second vertical discrete value is used as the right cropping boundary.
[0058] Starting from the top row of pixels in the vertical direction of the image to be processed, the horizontal discrete values are compared one by one with the horizontal discrete threshold. When a horizontal discrete value greater than the threshold appears for the first time, it is determined as the third horizontal discrete value. The pixel row corresponding to the third horizontal discrete value is used as the upper cropping boundary.
[0059] Starting from the horizontal discrete value corresponding to the bottom row of pixels in the vertical direction of the image to be processed, each value is compared with the horizontal discrete threshold. When a horizontal discrete value greater than the threshold appears for the first time, the next horizontal discrete value greater than the threshold is determined as the fourth horizontal discrete value. The pixel row corresponding to the fourth horizontal discrete value is used as the lower cropping boundary.
[0060] like Figure 3 As shown in the image example, the closed region in the image to be processed (or the original image) enclosed by the left cropping boundary, the right cropping boundary, the upper cropping boundary, and the lower cropping boundary is the processed image that is needed after cropping.
[0061] In one embodiment, the vertical discrete threshold and the horizontal discrete threshold can be set in any suitable manner according to the actual situation and needs, and the scope of protection of this disclosure is not limited to the specific values of the vertical discrete threshold and the horizontal discrete threshold.
[0062] In one approach, the vertical and horizontal discrete thresholds can be manually set to fixed values beforehand based on experience and / or experimental data. The vertical and horizontal discrete thresholds can be set to the same fixed value or different fixed values. When processing different images, the fixed vertical and horizontal discrete thresholds are used to determine the cropping boundaries.
[0063] In another approach, the corresponding vertical and horizontal discrete thresholds are determined based on the vertical and horizontal discrete values of the image to be processed. For example, the average of each vertical discrete value is used as the vertical discrete threshold, and the average of each horizontal discrete value is used as the horizontal discrete threshold. Alternatively, the minimum of each vertical discrete value is used as the vertical discrete threshold, and the minimum of each horizontal discrete value is used as the horizontal discrete threshold. Another example is using the median of each vertical discrete value as the vertical discrete threshold, and the median of each horizontal discrete value as the horizontal discrete threshold. Yet another example is obtaining the vertical discrete threshold based on each vertical discrete value using the following formula (2); and obtaining the vertical discrete threshold based on each horizontal discrete value using the following formula (2).
[0064] Discrete threshold = min(s) i )+thre*(max(s i )–min(s i (2);
[0065] Among them, s iThis represents each discrete value (horizontal or vertical), where min indicates the minimum value, max indicates the maximum value, and thre indicates the preset value. thre is preset; for example, if thre is set to 0.05, then thre = 0.05.
[0066] In this example, the vertical and horizontal discrete thresholds are set to fixed values, which can further reduce the amount of computation in the implementation process and speed up the calculation. The vertical and horizontal discrete thresholds are dynamically set according to the horizontal and vertical discrete values, which can make the vertical and horizontal discrete thresholds more suitable for the image to be processed and improve the accuracy of image cropping.
[0067] Step 105: Crop the image based on the vertical and horizontal cropping boundaries to obtain the processed image.
[0068] In this embodiment, after determining the vertical and horizontal cropping boundaries, image cropping can be performed to obtain the processed image after edge cropping.
[0069] In one embodiment, after scaling, grayscale conversion, or acceleration processing has been performed based on the above embodiments, in order to ensure the viewing quality of the image returned to the user, the image to be processed after the above processing cannot be directly cropped. Specifically, the image is cropped based on the vertical and horizontal cropping boundaries to obtain the processed image. The process is as follows: the vertical and horizontal cropping boundaries in the image to be processed are restored to at least one original cropping boundary in the original image; the original image is cropped based on the original cropping boundary to obtain the processed image.
[0070] In this embodiment, the vertical and horizontal cropping boundaries in the image to be processed need to be restored to the original image coordinates. The original image is then cropped to obtain the processed image. In this way, the processed image only has its edges cropped, while parameters such as image color and image sharpness remain unchanged, avoiding situations where the processed image after cropping lacks color and ensuring a good user experience.
[0071] In this embodiment, the processed image can be saved to a local disk or transmitted to a network or other storage device for further user operations.
[0072] The image processing method disclosed herein, after acquiring the image to be processed, calculates the vertical discrete value corresponding to at least one column and the horizontal discrete value corresponding to at least one row in the image to be processed, based on the pixel value of each pixel in the image to be processed. Then, the vertical and horizontal cropping boundaries are determined using the vertical and horizontal discrete values, respectively. Image cropping is performed based on the vertical and horizontal cropping boundaries to obtain the processed image. In this process, the pixel value of each pixel in the image to be processed is calculated, and the vertical and horizontal cropping boundaries are determined based on the calculated vertical and horizontal discrete values. The calculation method is simple, requiring no complex processing algorithms, eliminating the need for manual processing, and avoiding the huge computational load caused by complex calculations. This reduces the time spent on image cropping processing, improves the efficiency of image cropping, and enables rapid image cropping. Furthermore, the interval-based accelerated calculation process further improves the calculation speed and reduces the time spent on image processing. Especially for images such as ID photos with near-solid-color edges, low-computational-consumption cropping processing can be achieved.
[0073] The image processing apparatus provided in the embodiments of this disclosure will now be described. The image processing apparatus described below can be referred to in correspondence with the image processing method described above. For example... Figure 4 As shown, the image processing apparatus includes:
[0074] Image acquisition module 401 is used to acquire the image to be processed;
[0075] The pixel value acquisition module 402 is used to acquire the pixel value of each pixel in the image to be processed;
[0076] The calculation module 403 is used to calculate the vertical discrete value corresponding to at least one column of pixels in the image to be processed, and to calculate the horizontal discrete value corresponding to at least one row of pixels in the image to be processed, based on the pixel value.
[0077] The boundary determination module 404 is used to determine the vertical cropping boundary of the image to be processed based on the vertical discrete value, and to determine the horizontal cropping boundary of the image to be processed based on the horizontal discrete value.
[0078] The cropping module 405 is used to crop the image to be processed based on the vertical cropping boundary and the horizontal cropping boundary to obtain the processed image.
[0079] Figure 5 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 5As shown, the electronic device may include a processor 501, a communications interface 502, a memory 503, and a communication bus 504. The processor 501, communications interface 502, and memory 503 communicate with each other via the communication bus 504. The processor 501 can call logical instructions in the memory 503 to execute an image processing method. This method includes: acquiring an image to be processed; acquiring the pixel value of each pixel in the image to be processed; calculating, based on the pixel values, the vertical discrete values corresponding to at least one column of pixels in the image to be processed, and the horizontal discrete values corresponding to at least one row of pixels in the image to be processed; determining the vertical cropping boundary of the image to be processed based on the vertical discrete values, and determining the horizontal cropping boundary of the image to be processed based on the horizontal discrete values; and cropping the image based on the vertical and horizontal cropping boundaries to obtain a processed image.
[0080] Furthermore, the logical instructions in the aforementioned memory 503 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of this disclosure, essentially, or the parts that contribute to the prior art, or parts of the technical solutions, can be embodied in the form of software products. These computer software products are stored in a storage medium and include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0081] On the other hand, this disclosure also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer is able to execute the image processing method provided by the above methods. The method includes: acquiring an image to be processed; acquiring the pixel value of each pixel in the image to be processed; calculating, based on the pixel values, the vertical discrete values corresponding to at least one column of pixels in the image to be processed, and calculating the horizontal discrete values corresponding to at least one row of pixels in the image to be processed; determining the vertical cropping boundary of the image to be processed based on the vertical discrete values, and determining the horizontal cropping boundary of the image to be processed based on the horizontal discrete values; and cropping the image based on the vertical cropping boundary and the horizontal cropping boundary to obtain a processed image.
[0082] In another aspect, this disclosure also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is implemented to perform the image processing methods provided above. The method includes: acquiring an image to be processed; acquiring the pixel value of each pixel in the image to be processed; calculating, based on the pixel values, vertical discrete values corresponding to at least one column of pixels in the image to be processed, and horizontal discrete values corresponding to at least one row of pixels in the image to be processed; determining, based on the vertical discrete values, a vertical cropping boundary of the image to be processed, and determining, based on the horizontal discrete values, a horizontal cropping boundary of the image to be processed; and cropping the image based on the vertical and horizontal cropping boundaries to obtain a processed image.
[0083] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0084] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0085] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this disclosure, and are not intended to limit them. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure.
Claims
1. An image processing method, characterized by, The method comprises: acquiring a to-be-processed image; acquiring pixel values of each pixel in the to-be-processed image; calculating vertical discrete values corresponding to at least one column of pixels in the to-be-processed image based on the pixel values, and calculating horizontal discrete values corresponding to at least one row of pixels in the to-be-processed image, wherein the vertical discrete value is used to represent the discrete degree of the pixel values corresponding to a column of pixels, and the horizontal discrete value is used to represent the discrete degree of the pixel values corresponding to a row of pixels; determining a vertical cutting boundary of the to-be-processed image based on the vertical discrete values, and determining a horizontal cutting boundary of the to-be-processed image based on the horizontal discrete values; performing image cutting based on the vertical cutting boundary and the horizontal cutting boundary to obtain a processed image.
2. The image processing method of claim 1, wherein, The calculation of the vertical discrete values corresponding to at least one column of pixels in the to-be-processed image comprises: determining at least one column of first to-be-processed pixels in the to-be-processed image at intervals of a first preset number of pixels in the horizontal direction of the to-be-processed image; calculating the vertical discrete values corresponding to each column of the first to-be-processed pixels respectively. The calculation of the horizontal discrete values corresponding to at least one row of pixels in the to-be-processed image comprises: determining at least one row of second to-be-processed pixels in the to-be-processed image at intervals of a second preset number of pixels in the vertical direction of the to-be-processed image; calculating the horizontal discrete values corresponding to each row of the second to-be-processed pixels respectively.
3. The image processing method of claim 1, wherein, The calculation of the vertical discrete values corresponding to at least one column of pixels in the to-be-processed image comprises: determining the pixel values corresponding to at least one column of pixels in the to-be-processed image; calculating the variance of the pixel values column by column, and taking the variance of each column as the vertical discrete value corresponding to each column of pixels; The calculation of the horizontal discrete values corresponding to at least one row of pixels in the to-be-processed image comprises: determining the pixel values corresponding to at least one row of pixels in the to-be-processed image; calculating the variance of the pixel values row by row, and taking the variance of each row as the horizontal discrete value corresponding to each row of pixels.
4. The image processing method of claim 1, wherein, The vertical cutting boundary comprises a left cutting boundary and a right cutting boundary, and the horizontal cutting boundary comprises an upper cutting boundary and a lower cutting boundary. The determination of the vertical cutting boundary of the to-be-processed image based on the vertical discrete values comprises: determining a first vertical discrete value, wherein the first vertical discrete value is the first vertical discrete value greater than a vertical discrete threshold value from the left; taking the pixel column corresponding to the first vertical discrete value as the left cutting boundary; determining a second vertical discrete value, wherein the second vertical discrete value is the first vertical discrete value greater than the vertical discrete threshold value from the right; taking the pixel column corresponding to the second vertical discrete value as the right cutting boundary. The determination of the horizontal cutting boundary of the to-be-processed image based on the horizontal discrete values comprises: determining a third horizontal discrete value, wherein the third horizontal discrete value is the first horizontal discrete value greater than a horizontal discrete threshold value from the top; taking the pixel row corresponding to the third horizontal discrete value as the upper cutting boundary; determining a fourth horizontal discrete value, wherein the fourth horizontal discrete value is a first appearing horizontal discrete value greater than the horizontal discrete threshold value from below; taking the pixel row corresponding to the fourth horizontal discrete value as the lower cut boundary.
5. The image processing method of claim 2, wherein, Before the determining the at least one column of first to-be-processed pixels in the to-be-processed image in the horizontal direction at intervals of the first preset number of pixels, the method further includes: obtaining a preset number of pixel samples; obtaining a total number of columns of pixels of the to-be-processed image; calculating a first integer quotient of the total number of columns divided by the number of pixel samples; obtaining a total number of rows of pixels of the to-be-processed image; calculating a second integer quotient of the total number of rows divided by the number of pixel samples; taking the first integer quotient as the first preset number of pixels and taking the second integer quotient as the second preset number of pixels, or determining a maximum value of the first integer quotient and the second integer quotient and taking the maximum value as the first preset number of pixels and the second preset number of pixels respectively.
6. The image processing method of claim 1, wherein, The obtaining the to-be-processed image includes: obtaining an original image; performing grayscale processing on the original image to obtain the to-be-processed image; The obtaining the pixel value of each pixel in the to-be-processed image includes: obtaining the pixel value of each pixel based on the grayscale value of each pixel in the to-be-processed image.
7. The image processing method of claim 6, wherein, The performing image cutting based on the vertical cut boundary and the horizontal cut boundary to obtain a processed image includes: restoring the vertical cut boundary and the horizontal cut boundary in the to-be-processed image to at least one original cut boundary in the original image; performing cutting on the original image based on the original cut boundary to obtain the processed image.
8. An image processing apparatus characterized by comprising: The device is used to implement the image processing method in any one of claims 1 to 7, and the device includes: an image obtaining module, configured to obtain a to-be-processed image; a pixel value obtaining module, configured to obtain a pixel value of each pixel in the to-be-processed image; a calculating module, configured to calculate a vertical discrete value corresponding to at least one column of pixels in the to-be-processed image based on the pixel value and calculate a horizontal discrete value corresponding to at least one row of pixels in the to-be-processed image based on the pixel value; a boundary determining module, configured to determine a vertical cut boundary of the to-be-processed image based on the vertical discrete value and determine a horizontal cut boundary of the to-be-processed image based on the horizontal discrete value; a cutting module, configured to perform cutting on the to-be-processed image based on the vertical cut boundary and the horizontal cut boundary to obtain a processed image.
9. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor implements the image processing method in any one of claims 1 to 7 when executing the program.
10. A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program implements the image processing method in any one of claims 1 to 7 when executed by the processor.
Citation Information
Patent Citations
Image cutting method and device
CN110298858A