Image Processing Method, Apparatus, and Storage Medium
By determining the properties of media file elements and scaling the canvas and element positions according to the target size, the target image is generated, and the problems of low efficiency of media file generation and inflexible size adjustment are solved, and efficient multi-size adjustment is achieved.
Patent Information
- Application Number
- CN202210293355.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-23
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2042-03-23
AI Technical Summary
The media file generation efficiency required by multiple sizes in the prior art is low and the size adjustment is inflexible, which cannot meet the needs of different delivery scenarios.
By obtaining the original image and target size of the media file, determining the attributes of each element, and scaling the canvas and element sizes according to the size of the original image and the target size, adjusting the position of the element in the target image, and generating the target image.
Multi-size scaling is realized, design work is simplified, production efficiency is improved, user needs is met, and manual adjustment efficiency is solved. The problem of low manual adjustment efficiency and automatic device generation cannot meet user needs.
Smart Images

Figure CN114677432B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and particularly relates to an image processing method, apparatus and storage medium. Background Art
[0002] With the rapid development of the Internet, the promotion of media files is an essential part of each company or enterprise. Usually, a media file needs to be launched on multiple platforms and various electronic devices. Due to these different launch scenarios, the launch sizes of the media files are different. Therefore, the same media file needs to include multiple size types to adapt to different launch scenarios. Currently, based on the original media file, the size of the media file can be manually adjusted to meet the size requirements of the corresponding scenario. In the manual adjustment method, the adjustment efficiency is low. If the device automatically generates the target media file, the size of the currently generated media file is usually a fixed size, lacking visual beauty and unable to flexibly adjust the size according to user needs. Summary of the Invention
[0003] The purpose of the embodiments of the present invention is to provide an image processing method, apparatus and storage medium to at least solve the problems of low generation efficiency of media files with multiple size requirements and inflexible size adjustment.
[0004] To achieve the above purpose, the embodiments of the present invention provide an image processing method, including: obtaining the original image of the media file and the target size of the target image to be generated; determining the attributes of each element according to the positions of the elements in the original image; scaling the canvas size of the target image and the sizes of the elements according to the size of the original image and the target size; and adjusting the positions of the scaled elements in the target image according to the attributes of the elements to obtain the target image.
[0005] Further, the determining the attributes of each element according to the positions of the elements in the original image includes: determining the elements with the difference between the size and the canvas size of the original image within a set range as background elements; determining the elements completely distributed inside the canvas of the original image as normal elements; determining the elements with at least one side exceeding the canvas edge of the original image as overflow elements; and determining the elements with at least one side coinciding with the canvas edge of the original image as edge-attached elements.
[0006] Further, before the determining the attributes of each element according to the positions of the elements in the original image, the method further includes: using the visual direct-view method to obtain the true text area in the original image; and determining the true text area as the true position of the element where it is located.
[0007] Further, after determining the attributes of each element in the original image according to the positions of the elements, the method further includes: generating a pending alignment axis for each normal element in the original image in a one-dimensional direction, and determining the pixel value where each pending alignment axis is located; counting the number of pending alignment axes with the same pixel value in the same direction; and using the pending alignment axis with the largest number as the actual alignment axis of its corresponding normal element.
[0008] Further, the scaling of the canvas size of the target image and the sizes of the respective elements according to the size of the original image and the target size includes: setting the canvas size of the target image to the target size; when the element is a background element, scaling the background element by the maximum value of the ratio between the target size and the canvas size of the original image; when the element is a normal element, scaling the size of the normal element and the pixel value where its actual alignment axis is located according to the ratio between the target size and the size of the original image; and when the element is an overflow element or a border element, scaling the size of the overflow element and the size of the border element according to the ratio between the target size and the size of the original image.
[0009] Further, the adjustment of the positions of the respective elements after scaling in the target image according to the attributes of the respective elements includes: traversing the normal elements on all actual alignment axes, determining the pixel value by which the normal elements that overflow the canvas are offset, and moving the normal elements along their actual alignment axes into the canvas of the target image according to the offset pixel value; for the scaled overflow elements, adjusting the positions of the overflow elements in the target image according to the area of the overflow elements in the canvas of the original image; and for the scaled border elements, adjusting the positions of the border elements in the target image according to the side of the border elements that coincides with the edge of the canvas of the original image.
[0010] Further, after determining the attributes of the respective elements, the method further includes: traversing the overlapping relationships of all normal elements in the original image.
[0011] Further, after adjusting the positions of the respective elements after scaling in the target image, the method further includes: checking whether there are new overlapping relationships among all normal elements; and when there are new overlapping relationships, reducing the specified number of times in a preset ratio along the actual alignment axes of the normal elements in the new overlapping relationships to obtain the target image.
[0012] Correspondingly, an embodiment of the present invention further provides an image processing apparatus, including: an acquisition module, configured to acquire an original image of a media file and a target size of a target image to be generated; an attribute determination module, configured to determine attributes of each element according to positions of the elements in the original image; a scaling module, configured to scale a canvas size of the target image and sizes of the elements according to a size of the original image and the target size; and an adjustment module, configured to adjust positions of the scaled elements in the target image according to the attributes of the elements to obtain the target image.
[0013] Correspondingly, an embodiment of the present invention further provides a machine-readable storage medium, on which instructions are stored, and the instructions are used to cause a machine to execute the image processing method as described above.
[0014] Through the above technical solution, according to positions of each element in an original image of a media file provided by a user, attributes of the elements are determined, a canvas size of the target image and sizes of the elements are scaled according to a size of the original image and a target size of the target image to be generated, and then positions of the scaled elements in the target image are adjusted according to the attributes of the elements to obtain the target image. An embodiment of the present invention only needs the user to provide the original image of the media file and the target size, and can automatically generate the target image corresponding to the target size, realizing multi-size scaling, simplifying the design work, improving the production efficiency, solving both the problem of low manual adjustment efficiency in the prior art and the problem that automatic generation by a device cannot meet user requirements.
[0015] Other features and advantages of the embodiments of the present invention will be described in detail in the subsequent specific implementation part. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings are used to provide a further understanding of the embodiments of the present invention, and constitute a part of the specification, and are used to explain the embodiments of the present invention together with the following specific implementation, but do not constitute a limitation to the embodiments of the present invention. In the drawings:
[0017] Figure 1 is a flowchart of an image processing method provided by an embodiment of the present invention;
[0018] Figure 2 is an example diagram of elements with different attributes provided by an embodiment of the present invention;
[0019] Figure 3 is an example diagram of a text element provided by an embodiment of the present invention;
[0020] Figure 4 is an example diagram of a processing result of a normal element in the prior art;
[0021] Figure 5 It is an example diagram of the alignment axis of normal elements provided by an embodiment of the present invention;
[0022] Figure 6 It is an example diagram of the overflow of normal elements provided by an embodiment of the present invention;
[0023] Figure 7 It is an example diagram of an overlapping relationship provided by an embodiment of the present invention;
[0024] Figure 8 It is a schematic structural diagram of an image processing device provided by an embodiment of the present invention. Detailed implementation manners
[0025] The following will describe in detail the specific implementation manners of the embodiments of the present invention with reference to the accompanying drawings. It should be understood that the specific implementation manners described herein are only used to illustrate and explain the embodiments of the present invention, and are not used to limit the embodiments of the present invention.
[0026] The applicant found that if the media files of a theme need to be applied to different scenarios, it usually requires manual adjustment or automatic generation by the device, but the efficiency or user requirements cannot be guaranteed.
[0027] Figure 1 It is a schematic flowchart of an image processing method provided by an embodiment of the present invention. As Figure 1 shown, the method includes the following steps:
[0028] Step 101, obtain the original image of the media file and the target size of the target image to be generated;
[0029] Step 102, determine the attributes of each element according to the positions of the elements in the original image;
[0030] Step 103, scale the canvas size of the target image and the sizes of the respective elements according to the size of the original image and the target size;
[0031] Step 104, adjust the positions of the scaled elements in the target image according to the attributes of the elements and obtain the target image.
[0032] Among them, in the embodiment of the present invention, the original image of the media file is processed on the web side, and the media file is the media file that needs to be processed into the target image, which can be an advertisement on a website page, etc. In addition, the format of the original image is PSD format, including information such as pictures and texts.
[0033] In the embodiments of the present invention, the original image of the media file can be obtained through any appropriate means. For example, it can be from a gallery or uploaded by the user, etc. The number of target sizes of the target image can also be set according to actual needs. For example, it can be one size or multiple sizes.
[0034] When the original image is obtained, each element in the original image exists like a container box. Therefore, in step 102, the attributes of each element can be determined through the positions of the elements in the original image.
[0035] Specifically, an element with a difference between its size and the canvas size of the original image within a set range is determined as a background element. For example, when the difference between the width and height of the element and the width and height of the canvas is within 1%, the element is determined as a background element, and / or the error between the element and the canvas is within 3 pixels. An element that is completely distributed inside the canvas of the original image is determined as a normal element. An element with at least one side exceeding the canvas edge of the original image is determined as an overflow element. For example, one side or multiple sides can exceed the canvas edge of the original image. An element with at least one side coinciding with the canvas edge of the original image is determined as an edge - adhering element. As Figure 2 shown in the example of each element in the original image, the difference between the background element and the canvas is hardly noticeable. One side of one overflow element exceeds the canvas edge, and both sides of another overflow element exceed the canvas edge. One side of one edge - adhering element coincides with the canvas edge, and both sides of another edge - adhering element coincide with the canvas edge.
[0036] In an implementation manner of the embodiments of the present invention, there is a special element in the original image of the media file, which is the text element. Since there may be special effects or borders when inputting text, as Figure 3 shown, the text area will become the area where the cross - lines are located. If the attributes of the elements are determined using the area where the cross - lines are located, there will be deviations. As Figure 3 shown, if the attributes are determined as normal elements according to the cross - line positions of "I am text 1", and if the attributes are determined as overflow elements according to the cross - line positions of "I am text 2", but the slanted area of "I am text 2" is the real area of its text, and its attributes should be normal elements. Therefore, since the embodiments of the present invention are applied to the web - side, through the application program interface function of getBoundingClientRect provided by the browser, before determining the attributes of each element according to the positions of the elements in the original image, the visual direct - view method can be used to actually measure the real area of the text in the original image, and the real area of the text is determined as the real position of the element where it is located. That is to say, forFigure 3 The actual position of "I am text 2" in is the position of the diagonal area, which is also the true position of its element, thus determining that the attribute of its element is a normal element. Therefore, in the embodiments of the present invention, before determining the attribute of an element, the true position of the text element in the original image can be determined by the visual direct view method, and then accurate attribute information can be obtained in the subsequent attribute determination.
[0037] For step 103, according to the size of the original image and the target size, scale the canvas size of the target image and the sizes of the respective elements. The scaling of the canvas size, background elements, normal elements, overflow elements, and edge-attached elements will be described separately below.
[0038] Among them, set the canvas size of the target image according to the target size. For example, when the target size is 50*100, the canvas size of the target image is 50*100.
[0039] For background elements, scale the background elements by the maximum value of the ratio between the target size and the canvas size of the original image. For example, when the target size is 50*100, the canvas size of the original image is 100*50, and the size of the background element in the original image is 100*50, then the aspect ratios of the target size to the canvas size of the original image in width and height are 0.5 and 2 respectively, and the maximum value 2 in the ratio is the ratio for scaling the background element, so the background element is scaled to 200*100. It should be emphasized that the background element is allowed to overflow. Therefore, the scaled background element can overflow the canvas of the target image.
[0040] For normal elements, since the normal elements in the prior art are scaled with their respective centers of gravity as the center, as Figure 4 shown, it results in that the normal elements that are left-aligned in the original image no longer meet the condition of left-aligned arrangement after image processing. Therefore, in the embodiments of the present invention, for normal elements, the concept of an alignment axis is introduced. Among them, after determining the attributes of the respective elements according to the positions of the respective elements in the original image, for the normal elements in the original image, generate a pending alignment axis for each normal element in the original image in one-dimensional direction, in order to Figure 5Taking the normal elements in as an example, generate a left-aligned axis, a center X-aligned axis, and a right-aligned axis (or an upper-aligned axis, a center Y-aligned axis, and a lower-aligned axis) in one-dimensional direction. To facilitate the subsequent movement of the normal elements, it is necessary to determine the actual alignment axis of each normal element. Among them, after generating the pending alignment axis of each normal element, determine the pixel value where each pending alignment axis is located. Taking the left-aligned axis, the center X-aligned axis, and the right-aligned axis as an example, the pixel value where each pending alignment axis is located is the pixel value in the X direction. For example, there are 7 normal elements in the original image, and the pixel values where the pending alignment axes of the 7 normal elements are located are shown in Table 1 below.
[0041] After that, count the number of the pending alignment axes with the same pixel value in the same direction. Taking the normal elements in Table 1 as an example, take the pending alignment axis with the largest number as the actual alignment axis of its corresponding normal element.
[0042] Table 1
[0043]
[0044] Among them, starting from the pixel value 20 where the left-aligned axis of normal element 1 is located, check whether there is a left-aligned axis with the same pixel value. It is found that the pixel values where the left-aligned axes of normal elements 2, 3, and 4 are located are the same as that of normal element 1, that is, the number of left-aligned axes with the same pixel value 20 is 4; then check the pixel value 40 where the center X-aligned axis of normal element 1 is located, and there is no center X-aligned axis with the same pixel value as it, so the number of pending alignment axes with this pixel value is 1; check the pixel value 60 where the right-aligned axis of normal element 1 is located, and there is also no right-aligned axis with the same pixel value as it, so the number of pending alignment axes with this pixel value is 1. In summary, take the left-aligned axis with the largest number as its actual alignment axis.
[0045] Then, check the pixel value 20 where the left-aligned axis of normal element 2 is located. The situation is similar to that of normal element 1, and also take its left-aligned axis as its actual alignment axis.
[0046] For normal element 3, the number of left-aligned axes with the same pixel value 20 as its left-aligned axis is 4; the number of center X-aligned axes with the same pixel value 60 as its center X-aligned axis is 2; the number of right-aligned axes with the same pixel value 100 as its right-aligned axis is also 2. Therefore, take the left-aligned axis with the largest number as its actual alignment axis.
[0047] For normal element 4, the number of left-aligned axes with the same pixel value 20 as its left-aligned axis is 4; the number of center X-aligned axes with the same pixel value 50 as its center X-aligned axis is 1; the number of right-aligned axes with the same pixel value 100 as its right-aligned axis is 3. Therefore, take the left-aligned axis with the largest number as its actual alignment axis.
[0048] Since the pixel values of the actual alignment axes of the above-mentioned normal elements 1, 2, 3, and 4 are all 20, the above 4 normal elements are grouped elements. After the subsequent image processing is completed, the above 4 normal elements should still be elements arranged in left alignment.
[0049] For normal element 5, the number of left alignment axes with the same pixel value of 40 of its left alignment axis is 1, the number of center X alignment axes with the same pixel value of 60 of its center X alignment axis is 2, and the number of right alignment axes with the same pixel value of 80 of its right alignment axis is 3. Therefore, the right alignment axis with the largest number is used as the actual alignment axis of normal element 5.
[0050] For normal element 6, the number of left alignment axes with the same pixel value of 60 of its left alignment axis is 2, the number of center X alignment axes with the same pixel value of 80 of its center X alignment axis is 1, and the number of right alignment axes with the same pixel value of 100 of its right alignment axis is 2. For the pending alignment axes with the same number, the actual alignment axis is determined according to the canvas position of the normal element in the original image. Among them, if the normal element is completely or mostly on the left side of the canvas, its left alignment axis is used as its actual alignment axis; if the normal element is completely or mostly on the right side of the canvas, its right alignment axis is used as its actual alignment axis; if the parts of the normal element on both sides of the canvas are the same, its center X alignment axis is used as its actual alignment axis. Therefore, taking the example that normal element 6 is completely or mostly on the left side of the canvas, its left alignment axis is used as its actual alignment axis.
[0051] For normal element 7, the number of left alignment axes with the same pixel value of 60 of its left alignment axis is 2, the number of center X alignment axes with the same pixel value of 70 of its center X alignment axis is 1, and the number of right alignment axes with the same pixel value of 80 of its right alignment axis is 3. Therefore, the right alignment axis with the largest number is used as the actual alignment axis of normal element 7.
[0052] Since the pixel values of the actual alignment axes of the above-mentioned normal elements 5 and 7 are both 80, the above 2 normal elements are grouped elements. After the subsequent image processing is completed, the above 2 normal elements should still be elements arranged in left alignment.
[0053] For the normal element 8, since the number of undetermined alignment axes with the same pixel values on all its undetermined alignment axes is the same, which is 1. For undetermined alignment axes with the same number, the actual alignment axis is determined according to the canvas position of the normal element in the original image. Specifically, if the normal element is completely or mostly on the left side of the canvas, its left alignment axis is taken as its actual alignment axis; if the normal element is completely or mostly on the right side of the canvas, its right alignment axis is taken as its actual alignment axis; if the parts of the normal element on both sides of the canvas are the same, its central X alignment axis is taken as its actual alignment axis. Therefore, taking the example that the parts of the normal element 8 on both sides of the canvas are the same, its central X alignment axis is taken as its actual alignment axis. Finally, the actual alignment axes of all normal elements are shown in Table 2.
[0054] Table 2
[0055] Normal element 1,2,3,4 5,7 6 8 Actual alignment axis Left alignment axis - 20 Right alignment axis - 80 Left alignment axis - 60 Center X alignment axis - 100
[0056] As for the processing method of determining the actual alignment axis using the undetermined alignment axes generated in the Y direction, it is similar to the above and will not be elaborated here.
[0057] Through the above implementation, the actual alignment axis of each normal element is obtained. When scaling the normal element, according to the ratio between the size of the original image and the target size, the size of the normal element and the pixel value where its actual alignment axis is located are scaled. Among them, for the scaling of the size of the normal element, first calculate the product of the width and height of the target size P - target = W - target * H - target, and the product of the width and height of the original image P - original = W - original * H - original, and then calculate the square root of the ratio of the two. After that, the size of the normal element is scaled by this ratio, that is, the width and height of the normal element are scaled proportionally respectively. In addition, the pixel value where the actual alignment axis of the normal element is located also needs to be scaled. For example, if the undetermined alignment axis is generated in the X direction, then the final actual alignment axis of the normal element is also the left alignment axis, central X alignment axis, and right alignment axis in the X direction. When calculating the ratio between the size of the original image and the target size, only the ratio in the X direction, that is, the ratio of the width, is considered. If the width in the size of the original image is 100, the pixel value where the actual alignment axis of a certain normal element is located in the original image is 10, and the width in the target size is 50, then the ratio between the size of the original image and the target size is 0.5, and the pixel value where the actual alignment axis of this normal element is located in the target image is 5. As for the processing method of the undetermined alignment axes generated in the Y direction, it is similar to the above and will not be elaborated here.
[0058] When the element is an overflow element and a side - sticking element, scale the size of the overflow element and the size of the side - sticking element according to the ratio between the size of the original image and the target size. Similarly, first calculate the product of the width and height of the target size \(P_{-target}=W_{-target}*H_{-target}\), and the product of the width and height of the original image \(P_{-original}=W_{-original}*H_{-original}\), and then calculate the square root of the ratio of the two. After that, scale the size of the overflow element and the size of the side - sticking element by this ratio, that is, scale their width and height respectively. Among them, there may be a special case for the side - sticking element. When the side - sticking element is scaled, its size may be larger than the size of the canvas. Therefore, it is necessary to judge whether the width and height of the scaled side - sticking element are greater than the width and height of the target size. If either one is greater, multiply the scaled width and height by a preset coefficient respectively. For example, the preset coefficient is 0.9, and force - reduce the width and height of the side - sticking element.
[0059] After scaling the element, there may be a situation where it does not meet the user's requirements after scaling. Therefore, it is necessary to perform step 104 to adjust the positions of the scaled elements in the target image according to the attributes of each different element. Among them, the canvas and background elements during the scaling process are accurately scaled and do not need to be adjusted. The situations where the normal elements, overflow elements, and side - sticking elements may not meet the user's requirements after scaling will be described below.
[0060] First, traverse all the normal elements on the actual alignment axis, determine the pixel value by which the normal element that overflows the canvas is offset, and move the normal element along its actual alignment axis into the canvas of the target image according to the offset pixel value. For example, when the pixel value by which the normal element is offset is 50, that is, the pixel by which it overflows the canvas is 50, and its actual alignment axis is the right - alignment axis, then move the normal element 50 pixels along its right - alignment axis into the canvas of the target image. In addition, one thing to note is that when the normal element and other normal elements are grouped - related elements, then when determining the offset pixel value of the normal element, it is based on the maximum offset value in the grouped - related elements. Figure 6 Taking the grouped - related elements A, B, and C as an example, their actual alignment axis is the right - alignment axis. After scaling, all of these grouped - related elements overflow the canvas more or less. Then when determining the offset pixel value of the normal element, it should be based on the maximum offset value, that is, the pixel value \(f\) by which the grouped - related element C is offset, and move the entire grouped - related element \(f\) pixels into the canvas. That is to say, for grouped - related elements, when adjusting the offset pixel value, it is based on the maximum offset pixel value in the grouped - related elements, and move all the normal elements in the grouped - related elements.
[0061] For the scaled overflow element, adjust the position of the overflow element in the target image according to the area of the overflow element within the canvas of the original image. For example, when the area of the overflow element within the canvas of the original image accounts for 40% of its total area, then the scaled overflow element also needs to ensure that the area of it within the canvas of the target image accounts for 40% of its total area. Therefore, adjust the position of the overflow element in the target image according to this standard.
[0062] For the scaled edge - attached element, adjust the position of the edge - attached element in the target image according to the edge of the edge - attached element that coincides with the edge of the canvas of the original image. For example, when the right side of the edge - attached element coincides with the edge of the canvas of the original image, then after scaling, it should also be ensured that the right side of the edge - attached element coincides with the edge of the canvas of the target image. Therefore, adjust the position of the edge - attached element in the target image according to this standard.
[0063] Through the embodiments of the present invention, it only requires the user to provide the original image of the media file and the target size, and then the target image corresponding to the target size can be automatically generated, realizing multi - size scaling, simplifying the design work, improving the production efficiency, solving both the problem of low manual adjustment efficiency in the prior art and the problem that the automatic generation by devices cannot meet the user's needs.
[0064] In addition, in an implementation manner of the embodiments of the present invention, during the process of processing the original image, due to size scaling, the space of the canvas will change drastically, and there may be a phenomenon that non - overlapping elements overlap. If it is the overlap of some natural scenery elements, it does not affect the effect, but for some human figures, text elements, and even the trademarks of merchants, such overlap needs to be avoided as much as possible. Therefore, in the embodiments of the present invention, after determining the attributes of each element, traverse the overlap relationships of all normal elements in the original image to know which normal elements have overlap relationships and which do not. After adjusting the positions of the scaled elements in the target image, it is necessary to check whether there are new overlap relationships among all normal elements. When there are new overlap relationships, reduce the specified number of times in a preset proportion along the actual alignment axes of the normal elements in the new overlap relationships to obtain the target image. The preset proportion can be set according to user requirements, for example, it is 10%, and the specified number of times is at most 3 times. That is to say, perform 3 scalings of 10% along the respective actual alignment axes of the normal elements in the new overlap relationships. Controlling it within 3 times is because it is not allowed to overly reduce the normal elements in order to pursue non - overlapping between elements. Figure 7As shown in the figure, on the left is the overlapping relationship among the normal elements A, B, C, D, and E in the original image, where the normal elements C, D, and E are grouped elements, and there is an overlapping relationship between them and the normal element B. On the right is the scaled image, in which a new overlapping relationship appears, that is, the overlapping relationship between the normal element A and the normal element B. Therefore, only the overlapping relationship between the normal element A and the normal element B needs to be processed. That is to say, Figure 7 In the example of Figure 7 , it is only necessary to gradually reduce the scale along the respective actual alignment axes of the normal element A and the normal element B at a preset ratio. After the first reduction, if there is still an overlapping relationship between the two, continue to reduce at the preset ratio. After the second reduction, if there is no overlapping relationship between the two, the image at this time can be used as the target image. After the second reduction, if the overlapping relationship is still stored, continue to reduce. If there is still an overlapping relationship between the two after the third reduction, stop reducing and directly use the image at this time as the target image.
[0065] In addition, when there are grouped elements in the new overlapping relationship, when reducing the normal elements in the new overlapping relationship, reduce along the actual alignment axis of the grouped elements in the new overlapping relationship at a preset ratio for a specified number of times to obtain the target image, so as to ensure that the grouped elements are still in a grouped relationship after the overlapping relationship is adjusted.
[0066] Through the above implementation manner, it is ensured that important elements (for example, normal elements) will not overlap due to scaling during the image processing process, avoiding the problem that important elements are covered and affecting the display effect.
[0067] Correspondingly, Figure 8 is a schematic structural diagram of an image processing device provided by an embodiment of the present invention. As Figure 8 shown, the device 80 includes: an acquisition module 81, configured to acquire the original image of the media file and the target size of the target image to be generated; an attribute determination module 82, configured to determine the attributes of the respective elements according to the positions of the respective elements in the original image; a scaling module 83, configured to scale the canvas size of the target image and the sizes of the respective elements according to the size of the original image and the target size; an adjustment module 84, configured to adjust the positions of the respective elements after scaling in the target image according to the attributes of the respective elements and obtain the target image.
[0068] Further, the attribute determination module is specifically configured to: determine an element whose difference between the size and the canvas size of the original image is within a set range as a background element; determine an element that is completely distributed inside the canvas of the original image as a normal element; determine an element with at least one side exceeding the canvas edge of the original image as an overflow element; determine an element with at least one side coinciding with the canvas edge of the original image as an edge-attached element.
[0069] Further, the attribute determination module is further configured to: before determining the attributes of the respective elements according to the positions of the respective elements in the original image, use a visual direct-view method to obtain the true text region in the original image; determine the true position of the element where the true text region is located.
[0070] Further, the apparatus further includes an alignment axis generation module 85, configured to, after determining the attributes of the respective elements according to the positions of the respective elements in the original image, generate a pending alignment axis for each normal element in the original image in a one-dimensional direction, and determine the pixel value where each pending alignment axis is located; count the number of the pending alignment axes with the same pixel value in the same direction; use the pending alignment axis with the largest number as the actual alignment axis of its corresponding normal element.
[0071] Further, the scaling module is specifically configured to: set the canvas size of the target image to the target size; when the element is a background element, scale the background element by the maximum value of the ratio between the target size and the canvas size of the original image; when the element is a normal element, scale the size of the normal element and the pixel value where its actual alignment axis is located according to the ratio between the target size and the size of the original image; when the element is an overflow element and a side-attached element, scale the size of the overflow element and the size of the side-attached element according to the ratio between the target size and the size of the original image.
[0072] Further, the adjustment module is further configured to: traverse the normal elements on all the actual alignment axes, determine the pixel value by which the normal element that overflows the canvas is offset, and move the normal element along its actual alignment axis into the canvas of the target image according to the offset pixel value; for the scaled overflow element, adjust the position of the overflow element in the target image according to the area of the overflow element in the canvas of the original image; for the scaled side-attached element, adjust the position of the side-attached element in the target image according to the side of the side-attached element that coincides with the edge of the canvas of the original image.
[0073] Further, the apparatus further includes an overlapping relationship determination module 86, configured to traverse the overlapping relationships of all the normal elements in the original image after determining the attributes of the respective elements.
[0074] Further, the adjustment module is further configured to: after adjusting the positions of the respective elements in the target image after scaling, check whether there are new overlapping relationships among all normal elements; when there are new overlapping relationships, reduce the specified number of times by a preset ratio along the actual alignment axis of the normal elements in the new overlapping relationships to obtain the target image.
[0075] The specific working principle and benefits of the image processing device provided by the embodiments of the present invention are similar to those of the image processing method provided by the embodiments of the present invention, and will not be elaborated here.
[0076] In addition, on the other hand, an embodiment of the present invention further provides a machine-readable storage medium, on which instructions are stored, and the instructions are used to cause a machine to execute the image processing method described in the above embodiments.
[0077] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0078] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, and the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0079] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device, and the instruction device implements the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0080] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one process Figure 1 one process or multiple processes and / or blocks Figure 1 steps of the functions specified in one block or multiple blocks.
[0081] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0082] The memory may include non-permanent memory in the computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of a computer-readable medium.
[0083] Computer-readable media includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0084] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, commodity or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the existence of additional identical elements in the process, method, commodity or device comprising the element.
[0085] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memory, CD-ROM, optical memory, etc.) containing computer-usable program code.
[0086] The above are only the embodiments of the present application and are not used to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. An image processing method, characterized in that, Including: Obtaining the original image of the media file and the target size of the target image to be generated; Determining the attributes of each element according to the positions of the elements in the original image; Scaling the canvas size of the target image and the sizes of each element according to the size of the original image and the target size; Adjusting the positions of the scaled elements in the target image according to the attributes of each element to obtain the target image, wherein, determining the attributes of each element according to the positions of the elements in the original image includes: Determining an element with a difference between its size and the canvas size of the original image within a set range as a background element; Determining an element that is completely distributed inside the canvas of the original image as a normal element; Determining an element with at least one side exceeding the canvas edge of the original image as an overflow element; Determining an element with at least one side coinciding with the canvas edge of the original image as an edge-attached element, wherein, after determining the attributes of each element according to the positions of the elements in the original image, the method further includes: Generating a pending alignment axis for each normal element in the original image in a one-dimensional direction and determining the pixel value where each pending alignment axis is located; Counting the number of pending alignment axes with the same pixel value in the same direction; Taking the pending alignment axis with the largest number as the actual alignment axis of its corresponding normal element.
2. The image processing method according to claim 1, wherein Before determining the attributes of each element according to the positions of the elements in the original image, the method further includes: Using the visual direct-view method to obtain the true text region in the original image; Determining the true text region as the true position of the element where it is located.
3. The image processing method according to claim 1, wherein Scaling the canvas size of the target image and the sizes of each element according to the size of the original image and the target size includes: Setting the canvas size of the target image with the target size; When the element is a background element, scaling the background element with the maximum ratio between the target size and the canvas size of the original image; When the element is a normal element, scaling the size of the normal element and the pixel value where its actual alignment axis is located according to the ratio between the target size and the size of the original image; When the element is an overflow element or an edge-attached element, scaling the size of the overflow element and the size of the edge-attached element according to the ratio between the target size and the size of the original image.
4. The image processing method according to claim 1, characterized in that Adjusting the positions of the scaled elements in the target image according to the attributes of each element includes: Traversing the normal elements on all actual alignment axes, determining the pixel value by which the normal elements that overflow the canvas are offset, and moving the normal elements along their actual alignment axes into the canvas of the target image according to the offset pixel value; For the scaled overflow element, adjusting the position of the overflow element in the target image according to the area of the overflow element in the canvas of the original image; For the scaled edge element, adjust the position of the edge element in the target image according to the edge that coincides with the canvas edge of the original image.
5. The image processing method according to claim 1, characterized in that After determining the attributes of each element, the method further includes: Traverse and record the overlapping relationships of all normal elements in the original image.
6. The image processing method according to claim 5, wherein After adjusting the positions of the scaled elements in the target image, the method further includes: Check whether there are new overlapping relationships among all normal elements; When there are new overlapping relationships, reduce the specified number of times at a preset ratio along the actual alignment axis of the normal elements in the new overlapping relationships to obtain the target image.
7. An image processing apparatus, characterized in that, Includes: An acquisition module for acquiring the original image of the media file and the target size of the target image to be generated; An attribute determination module for determining the attributes of each element according to the positions of the elements in the original image; A scaling module for scaling the canvas size of the target image and the sizes of each element according to the size of the original image and the target size; An adjustment module for adjusting the positions of the scaled elements in the target image according to the attributes of each element and obtaining the target image. Among them, the attribute determination module is specifically used to: determine an element with a difference between its size and the canvas size of the original image within a set range as a background element; determine an element that is completely distributed inside the canvas of the original image as a normal element; determine an element with at least one edge exceeding the canvas edge of the original image as an overflow element; determine an element with at least one edge coinciding with the canvas edge of the original image as an edge element. The device further includes an alignment axis generation module for generating a pending alignment axis for each normal element in the original image in a one-dimensional direction and determining the pixel value where each pending alignment axis is located after determining the attributes of each element according to the positions of the elements in the original image; counting the number of pending alignment axes with the same pixel value in the same direction; taking the pending alignment axis with the largest number as the actual alignment axis of its corresponding normal element.
8. A machine-readable storage medium, characterized in that, Instructions are stored on the machine-readable storage medium, and the instructions are used to cause the machine to execute the image processing method according to any one of claims 1-6.
Citation Information
Patent Citations
Element arrangement method and device, computer readable storage medium and equipment
CN110780872A
Picture generation method and device, electronic equipment and readable storage medium
CN112164127A