Image cropping method, device, electronic device and storage medium
By detecting the center point of the connected area during image cropping and performing cropping based on the center point, the problem of inaccurate image cropping in the prior art is solved, and cropping of the complete image body is achieved.
Patent Information
- Application Number
- CN202110042473.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-13
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2041-01-16
AI Technical Summary
The existing technology is difficult to accurately crop images, especially when the background is complex, and it is easy for part of the target subject to exist in the cropped image.
By obtaining the image to be cropped and the cropping size, the image subject is detected, the center point of the connected area is determined, and cropping is performed based on the center point and the cropping size to ensure that the cropped image contains the complete image subject.
Improves the accuracy of image cropping, avoids partial capture of the image subject, and ensures the integrity of the image subject in the cropped image.
Smart Images

Figure CN113538502B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing and artificial intelligence technology. Specifically, the present application relates to a method, device, electronic device and storage medium for image cropping. Background Art
[0002] With the development of electronic and artificial intelligence technologies, the display sizes of different terminal devices vary greatly, such as advertising screens on billboards and mobile terminals. If the same image needs to be displayed normally on different terminal devices, the image needs to be cropped. Even if it is displayed on the same terminal device, there are cases where the image needs to be cropped. For example, when a video / album cover image is switched from horizontal to vertical display, a picture needs to adapt to both horizontal and vertical screen requirements, so the image needs to be cropped.
[0003] Existing technologies often use saliency algorithms to crop images, using a block-based approach to calculate the background, calibrate the background of the image, and then crop the background. However, this image cropping method cannot accurately crop images with complex backgrounds, and it is easy for parts of the target subject to remain in the cropped image. Summary of the Invention
[0004] The purpose of this application is to solve at least one of the above-mentioned technical defects, and the following technical solution is proposed to solve the problem of inaccurate image cropping.
[0005] In one aspect of the present application, a method for cropping an image is provided, comprising:
[0006] Get the image to be cropped and the cropping size;
[0007] Performing image subject detection on the image to be cropped to obtain the center point of a connected area covering at least one image subject in the image to be cropped;
[0008] The image to be cropped is cropped based on the center point of the connected region and the cropping size to obtain a cropped image containing at least one image body.
[0009] Another aspect of the present application provides a picture cropping device, the device comprising:
[0010] The acquisition module is used to obtain the image to be cropped and the cropping size;
[0011] A subject detection module is used to detect the subject of the image to be cropped and obtain the center point of the connected area covering at least one subject in the image to be cropped;
[0012] The cropping module is used to crop the image to be cropped based on the center point of the connected area and the cropping size to obtain a cropped image containing at least one image body.
[0013] In another aspect of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the image cropping method shown in the first aspect of the present application is implemented.
[0014] In another aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the image cropping method shown in the first aspect of the present application is implemented.
[0015] The beneficial effects of the technical solution provided by this application are:
[0016] The image cropping method provided in the present application determines the width and height of the cropping frame according to the cropping size, and obtains a cropped image containing at least one image body based on the center of the connected area and the cropping size. The cropped image can display the main content of the image to be cropped, thereby improving the accuracy of image cropping. Moreover, since the cropping method is based on the image body, it can avoid the situation where any image body in the image to be cropped is partially intercepted, thereby ensuring that the image bodies in the cropped image are all complete image bodies.
[0017] Additional aspects and advantages of the present application will be given in part in the following description, which will become apparent from the following description, or will be learned through practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0019] Figure 1 A schematic diagram of an implementation environment of a picture cropping method provided in one embodiment of the present application;
[0020] Figure 2 A flowchart of a method for cropping an image provided in one embodiment of the present application;
[0021] Figure 3-1 A schematic diagram showing a rectangular frame marking the area where each individual face in a picture to be cropped is located, provided in one embodiment of the present application;
[0022] Figure 3-2 A schematic diagram of obtaining a connected area covering at least one face based on the area of each individual face in the image to be cropped, provided in another embodiment of the present application;
[0023] Figure 4A flowchart for determining the center point of a connected area provided in one embodiment of the present application;
[0024] Figure 5-1 、 Figure 5-2 A schematic diagram of determining the cropping position based on the original image size, cropping size, and the center point of the connected area provided in one embodiment of the present application. Figure 5-1 The image to be cropped is displayed. Figure 5-2 The image corresponding to the cropping position determined based on the original image size, cropping size, and center point of the connected area of the image to be cropped;
[0025] Figure 6 This is a schematic diagram of the interface of the second picture provided in one embodiment of the present application;
[0026] Figure 7 A schematic diagram of the structure of a picture cropping device provided in one embodiment of the present application;
[0027] Figure 8 A schematic structural diagram of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0028] The following describes embodiments of the present application in detail. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application and are not to be construed as limiting the present application.
[0029] It will be understood by those skilled in the art that, unless expressly stated otherwise, the singular forms "a", "an", "said" and "the" used herein may also include the plural forms. It should be further understood that the term "comprising" used in the specification of this application refers to the presence of features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be intermediate elements. In addition, "connected" or "coupled" as used herein may include wireless connections or wireless couplings. The term "and / or" used herein includes all or any units and all combinations of one or more associated listed items.
[0030] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those skilled in the art in the art to which the present invention pertains. It should also be understood that terms such as those defined in common dictionaries should be understood to have meanings consistent with their meanings in the context of the prior art and, unless specifically defined as herein, will not be interpreted in an idealized or overly formal sense.
[0031] Saliency detection: Extract salient areas (i.e. areas of interest to users) in an image using artificial intelligence algorithms.
[0032] Face region feature binary map: a binary map marking the face region and non-face region in the image.
[0033] Saliency feature binary map: a binary map that marks the salient and insignificant areas in the image.
[0034] During the research process, the inventors also found that when using a face detection algorithm to detect faces and determine the face position, if the image contains multiple faces, one of the faces may be used as the main body of the image, and parts of the faces of other faces in the image may be cut off.
[0035] The solution provided in the embodiments of the present application can be executed by any electronic device, such as a terminal device or a server, wherein the server can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services. The terminal device can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, a smart TV, a smart car device, etc., but is not limited to this. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, and this application does not limit this. With respect to the technical problems existing in the prior art, the image cropping method, device, electronic device and storage medium provided in this application are intended to solve at least one of the technical problems of the prior art.
[0036] Figure 1This is a schematic diagram of an implementation environment for an image cropping method provided in one embodiment of the present application. The implementation environment in this example may include, but is not limited to, a server 101, a network 102, and a terminal device 103. Server 101 can communicate with terminal device 103 via network 102. Server 101 can send a cropped image to terminal device 103 via the network. Terminal device 103 includes a human-computer interaction screen 1031, a processor 1032, and a memory 1033. Human-computer interaction screen 1031 is used to display the image to be cropped and related information about the cropped image. Memory 1033 is used to store data related to the image to be cropped and the cropped image. Server 101 includes a database 1011 and a processing engine 1012. Terminal device 103 can upload the image to be cropped to server 101 via the network. Server 101 crops the image to be cropped to obtain a cropped image, and then sends the cropped image to terminal device 103 for display.
[0037] Among them, the terminal device 103 can be used to run a client that provides a picture display function. The specific form is not limited. The client provides a picture display function, such as a media player, a browser, etc. It can be in the form of an application or a web page, and there is no limitation here.
[0038] In one embodiment of the present application, the solution provided in the embodiment of the present application can be implemented based on cloud technology, and the data processing involved in each optional embodiment (including but not limited to data calculation, etc.) can be implemented using cloud computing. Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and network within a wide area network or local area network to achieve data calculation, storage, processing, and sharing. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. applied in the cloud computing business model. It can form a resource pool that can be used on demand and is flexible and convenient. Cloud computing technology will become an important support. The backend services of technical network systems require a large amount of computing and storage resources, such as video websites, image websites, and more portal websites. With the rapid development and application of the Internet industry, in the future, each item may have its own identification mark and need to be transmitted to the backend system for logical processing. Data of different levels will be processed separately. All kinds of industry data require strong system backend support, which can only be achieved through cloud computing.
[0039] Cloud computing is a computing model that distributes computing tasks across a resource pool consisting of a large number of computers, enabling various application systems to access computing power, storage space, and information services as needed. The network that provides these resources is called the "cloud." To users, these resources appear infinitely scalable and can be accessed at any time, used on demand, expanded at any time, and paid for on a per-use basis.
[0040] As a provider of cloud computing infrastructure capabilities, a cloud computing resource pool (referred to as a cloud platform, generally referred to as an IaaS (Infrastructure as a Service) platform) is established. Various types of virtual resources are deployed in the resource pool for external customers to choose from. The cloud computing resource pool mainly includes computing devices (virtualized machines, including operating systems), storage devices, and network devices. Based on logical functional divisions, the PaaS (Platform as a Service) layer can be deployed on the IaaS (Infrastructure as a Service) layer, and the SaaS (Software as a Service) layer can be deployed on the PaaS layer. SaaS can also be deployed directly on IaaS. PaaS is a platform for software operation, such as databases and web containers. SaaS is a variety of business software, such as web portals and text message senders. Generally speaking, SaaS and PaaS are upper layers relative to IaaS.
[0041] The following specific embodiments describe in detail the technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0042] The present application embodiment provides a possible implementation method, such as Figure 2 As shown, a flowchart of a method for cropping an image is provided. The solution can be executed by any electronic device. For example, the solution of the embodiment of the present application can be executed on a terminal device or a server, or executed by the terminal device and the server together. By obtaining the image to be cropped and the cropping size, the image to be cropped is cropped so that the cropped image contains the image body. For the convenience of description, the method provided by the embodiment of the present application will be described below using the server as the execution subject as an example. Figure 2 As shown in the flowchart, the method may include the following steps:
[0043] Step S110, obtaining the image to be cropped and the cropping size;
[0044] Step S120, performing image subject detection on the image to be cropped, and obtaining a center point of a connected area covering at least one image subject in the image to be cropped;
[0045] Step S130 , cropping the image to be cropped based on the center point of the connected area and the cropping size to obtain a cropped image containing at least one image body.
[0046] This embodiment provides a solution that requires cropping the same image to accommodate different display sizes when displayed on different terminal devices. The image to be cropped is referred to as the image to be cropped. The cropped image can adapt to different display size requirements. Furthermore, the cropped image can be processed again to obtain a new image, such as an advertisement or poster with a slogan. However, if the image to be cropped is cropped only to meet the size requirement, the cropped image may not contain or contain part of the image body, resulting in the cropped image not meeting the requirements.
[0047] To address this situation, the present application provides a method for image cropping. First, the image to be cropped and the cropping size are obtained, where the cropping size is a pre-set size of the cropped image. Then, the image subject is detected on the image to be cropped. When the image to be cropped contains a face, the image subject of the image to be cropped is the face. When the image to be cropped does not contain a face, the image subject of the image to be cropped is the salient area, and the salient area is the non-background area.
[0048] After the image to be cropped is subjected to image subject detection, the image subject is obtained, and the image subject can be marked, such as: the outer boundary of the image subject can be framed with a rectangular frame, and the rectangular frame can be called the outer frame of the image subject. If the image to be cropped contains at least one image subject, and each image subject is marked with a rectangular frame, then after the image to be cropped is subjected to image subject detection, at least one rectangular frame for framing the image subject is obtained on the image to be cropped, and a connected area covering the at least one image subject is obtained based on the at least one rectangular frame, and the center point of the connected area is obtained. If there is one image subject, the connected area is the outer frame of the image subject. If there are two or more image subjects, the connected area is the area covering the two or more image subjects. In one embodiment of the present application, the outer frame of each image subject is expanded until the outer frames of the two image subjects are connected or there is an intersection, and the area covered by the outer frames of the two image subjects is the connected area.
[0049] The image to be cropped is cropped based on the center point of the connected area and a preset cropping size to obtain a cropped image containing at least one image body.
[0050] In one embodiment of the present application, the cropping size is the cropping width and height, or it can be the cropping diameter, etc., with the center point of the connected area as the center. When the cropping size is the cropping width and height, the width and height of the cropping frame are determined according to the cropping size, and a cropped image containing at least one image subject is obtained based on the center of the connected area and the cropping size. The cropped image is an image containing at least one image subject in the image to be cropped. Therefore, the cropped image can show the main content of the image to be cropped. Moreover, since the cropping method is based on the image subject, it can avoid the situation where any image subject in the image to be cropped is partially intercepted, thereby ensuring that the image subjects in the cropped image are complete image subjects.
[0051] The image cropping method provided in the embodiment of the present application obtains a cropped image containing at least one image body based on the center of the connected area and the cropping size, thereby avoiding the situation where half of the image body appears in the cropped image, which is conducive to improving the accuracy of image cropping.
[0052] In order to make the technical solution provided by this application clearer, the solution provided by this application is described below through specific examples:
[0053] In one embodiment of the present application, when the image subject includes a face, step S120 provides performing image subject detection on the image to be cropped to obtain the center point of a connected area covering at least one image subject in the image to be cropped, including:
[0054] A1, perform face detection on the cropped image to obtain a binary feature map of the face area;
[0055] A2: If the face region feature binary map is valid, determine a connected region covering at least one face in the image to be cropped based on the face region feature binary map, and determine the center point of the connected region.
[0056] Face detection can be performed on the cropped image using a face detection algorithm, such as the MTCNN (Multi-task Cascaded Convolutional Networks) algorithm, to generate a binary face region feature map. This algorithm can achieve both accurate face detection and real-time face detection on a CPU. In this binary face region feature map, the pixel values for face areas are 1, and the pixel values for non-face areas are 0.
[0057] If a region with a value of 1 is detected in the face region feature binary map, the face region feature binary map is determined to be valid, and the image to be cropped contains a face, and the main body of the image is a face. The face is marked according to the face region feature binary map, such as by marking the region where each single face in the image to be cropped is located with a rectangular frame, such as Figure 3-1As shown in the figure, the image to be cropped contains two faces, face A and face B. Each face is marked with a rectangular frame. The rectangular frame corresponding to face A and the rectangular frame corresponding to face B are not connected to each other. Then, the connected area covering at least one face is obtained based on the area of each single face in the image to be cropped, as shown in the figure. Figure 3-2 As shown in the figure, a connected region can be used to cover the two faces in the image to be cropped. The connected region can be a regular region or an irregular region. The center point of the connected region is then obtained by solving the algorithm for finding the center point of the graph.
[0058] In one embodiment of the present application, the method provided by A2 for determining a connected area covering at least one face in the image to be cropped based on the face region feature binary map may be performed in the following manner, including:
[0059] A21, determining the coverage area of each individual face in the image to be cropped based on the face region feature binary map;
[0060] A22, dilate the coverage area of each individual face to obtain a connected area covering at least one face in the image to be cropped.
[0061] Since the value of the face area in the face area feature binary image is 1, the coverage area of each single face in the to-be-cropped image is determined according to the area with a value of 1 in the face area feature binary image.
[0062] The coverage area of a single face is expanded, such as by using a dilation algorithm or a preset dilation coefficient to expand the coverage area of a single face, to obtain a connected area covering at least one face in the image to be cropped.
[0063] In one embodiment of the present application, when there is only one face in the image to be cropped, the coverage area is expanded with an expansion coefficient of 1 to obtain a connected area covering at least one face in the image to be cropped. When there are two or more faces in the image to be cropped, the coverage area of each single face is expanded with a preset expansion coefficient so that the boundaries of the coverage areas of adjacent single faces intersect or connect, such as Figure 3-2 As shown, the coverage area of face A and the coverage area of face B have overlapping areas after dilation processing. When there is an overlapping area, the area covering face A and face B is regarded as a connected area.
[0064] The solution provided in this embodiment dilates the coverage area of a single face. The dilation process connects adjacent unconnected face areas into a connected area. The connected area can cover at least one face in the image to be cropped. The connected area covers at least one face and the face coverage area is complete, which is beneficial to improving the accuracy of the cropping area determined based on the center point of the connected area.
[0065] When the face region feature binary map is invalid, that is, the image to be cropped does not contain a face, the present application further provides an embodiment for performing image subject detection on the image to be cropped to obtain the center point of a connected area covering at least one image subject in the image to be cropped. This can be performed in the following manner, including:
[0066] B1, perform saliency detection on the cropped image to obtain a binary saliency feature map;
[0067] B2: Based on the binary salient feature map, a connected region covering at least one salient region in the image to be cropped is obtained, and a center point of the connected region is determined.
[0068] Saliency detection can be performed on the image to be cropped using a saliency detection algorithm, such as the RAS algorithm (Reverse Attention for Salient Object Detection), to generate a binary map of salient features. Since there are no faces in the image to be cropped, the image's main body is the salient region, representing the area of interest to the user. For example, in a landscape image, the salient region can be the target area excluding the background and foreground. In the binary map, salient regions are assigned a value of 1, while the remaining regions are assigned a value of 0. Based on the binary map, the position of each salient region in the image to be cropped can be determined. Based on the positions of each salient region, a connected region is formed that covers at least one salient region in the image to be cropped. When there is only one main body, the connected region is the bounding box of the single salient region. When there are at least two main bodies, the connected region is the region covering at least two adjacent regions. The center point of the connected region is then determined using an algorithm for finding the center point of the graph.
[0069] In one embodiment of the present application, obtaining a connected region covering at least one salient region in the image to be cropped based on the salient feature binary map provided in B2 can be performed in the following manner, including:
[0070] B21, determining at least one salient region in the image to be cropped based on the salient feature binary map;
[0071] B22: dilate the at least one salient region to obtain a connected region covering the at least one salient region in the image to be cropped.
[0072] Since the value of the salient region in the salient feature binary map is 1, the salient region in the to-be-cropped image is determined based on the region whose value is 1 in the salient feature binary map.
[0073] Each salient region is expanded, for example, by using a dilation algorithm or a preset dilation coefficient to expand each salient region, to obtain a connected region covering at least one salient region in the image to be cropped.
[0074] In one embodiment of the present application, when there is only one salient region in the image to be cropped, the salient region is dilated with a dilation coefficient of 1 to obtain a connected region covering at least one salient region in the image to be cropped. When there are two or more salient regions in the image to be cropped, each salient region is dilated with a preset dilation coefficient so that the boundaries of adjacent salient regions intersect or connect, thereby achieving connectivity between the adjacent salient regions. The region covered by the salient regions with intersecting or connecting boundaries is then considered a connected region.
[0075] The solution provided in this embodiment performs dilation processing on the salient area. The dilation processing connects adjacent unconnected salient areas into a connected area. The connected area can cover at least one salient area in the image to be cropped, and the covered salient area is a complete salient area. This helps to improve the accuracy of the cropping area of the cropped image determined based on the center point of the connected area.
[0076] Figure 4 The flowchart of determining the center point of the connected area provided in one embodiment of the present application includes: first, the solution provided in S110 to S120 can be used to obtain the image to be cropped and the cropping size, and the image subject is detected in the image to be cropped to obtain the face area feature binary map (corresponding to Figure 4 Then detect whether the face area feature binary map is valid (corresponding to S410); Figure 4 If valid, the coverage area of each single face in the image to be cropped is determined based on the face area feature binary map (corresponding to Figure 4 A21 in ); dilate the coverage area of each single face to obtain a connected area covering at least one face in the image to be cropped (corresponding to Figure 4 If invalid, perform saliency detection on the cropped image to obtain a saliency feature binary map (corresponding to Figure 4 B1 in ); Based on the salient feature binary map, a connected area covering at least one salient area in the image to be cropped is obtained (corresponding to Figure 4 B2 in the .
[0077] The solution provided in this embodiment first performs face detection on the image to be cropped. If a face is detected, the image body is the face. If no face is detected, saliency detection is used to obtain a salient area, with the image body being the salient area. Based on the face or the salient area, a connected area covering at least one image body is determined, and then the center point of the connected area is determined. This is conducive to accurately and efficiently determining the image body and the center point of the connected area of the image to be cropped.
[0078] According to the solution provided in the above embodiment, after determining the center point of the connected region, the present application further provides an embodiment for cropping the image to be cropped based on the center point of the connected region and the cropping size to obtain a cropped image containing at least one image body. This can be performed in the following manner, including:
[0079] C1, obtain the original image size of the image to be cropped;
[0080] C2, determine the cropping position of the cropped image based on the relationship between the original image size and the cropping size, as well as the center point of the connected area;
[0081] C3, cropping the image to be cropped according to the cropping position to obtain a cropped image containing at least one image subject.
[0082] The embodiments of the present application provide a method for determining a cropped image. The method determines the cropping position of the cropped image based on the original image size, the cropping size, and the center point of the connected region of the image to be cropped. The image to be cropped is then cropped based on the cropping position to obtain a cropped image containing at least one image subject. The cropping position and cropped image obtained using this method not only ensure that the cropped image contains the image subject, but also ensure the integrity of the captured image subject.
[0083] In particular, when the cropping size of the cropped image is significantly different from the original image size of the image to be cropped, directly using the cropping size and the center point of the connected area to determine the cropping position will result in the inability to capture the complete image subject. Therefore, the present application combines the relationship between the original image size and the cropping size, as well as the center point of the connected area to determine the cropping position of the cropped image, which is conducive to improving the integrity of the image subject in the cropped image, and thus improving the accuracy of the cropping position of the cropped image. For example, when the original image size is significantly different from the cropping size, the original image size can be adjusted first so that the difference between the adjusted original image size and the cropping size is within a reasonable range, avoiding the situation where only part of the image subject in the cropped image is captured. Here, part of the image subject can refer to a part of a single image subject, such as a partial area of a single face, which results in poor visual quality or unusability of the cropped image.
[0084] When the size in the embodiment is height and width, that is, the original image size includes the original image height and the original image width, and the cropped size includes the cropped width and the cropped height, in one embodiment of the present application, C2 provides a method for determining the cropping position of the cropped image based on the relationship between the original image size and the cropped size and the center point of the connected area, which can be performed in the following manner, including:
[0085] C21, when the aspect ratio corresponding to the original image size is greater than the aspect ratio corresponding to the cropped size, adjusting the width corresponding to the original image size based on the height corresponding to the original image size and the aspect ratio corresponding to the cropped size so that the aspect ratio corresponding to the adjusted original image size is consistent with the aspect ratio corresponding to the cropped size, and determining the cropping position of the cropped image based on the adjusted original image size and the center point of the connected area;
[0086] C22: When the aspect ratio of the original image size is smaller than the aspect ratio of the cropped image size, the height of the original image size is adjusted based on the width of the original image size and the aspect ratio of the cropped image size, so that the aspect ratio of the adjusted original image size is consistent with the aspect ratio of the cropped image size. The cropping position of the cropped image is determined based on the adjusted original image size and the center point of the connected area.
[0087] C23, when the aspect ratio corresponding to the original image size is consistent with the aspect ratio corresponding to the cropped image size, the cropping position of the cropped image is determined according to the original image size and the center point of the connected area.
[0088] Specifically, the aspect ratio corresponding to the original image size and the aspect ratio corresponding to the cropped size of the image to be cropped are obtained, and the cropping position of the cropped image is determined based on the relationship between the aspect ratio corresponding to the original image size and the aspect ratio corresponding to the cropped size, and the center point of the connected area.
[0089] When the aspect ratio corresponding to the original image size is consistent with the aspect ratio corresponding to the cropped size, the cropping position of the cropped image is determined according to the original image size and the center point of the connected area.
[0090] If the aspect ratio of the original image size is inconsistent with the aspect ratio of the cropped image size, the original image size is adjusted so that the aspect ratio of the adjusted original image size is equal to the aspect ratio of the cropped image size. Then, the cropping position of the cropped image is determined with the center point of the connected region as the center and the adjusted original image size as the screenshot size. The image corresponding to the cropping position contains at least one image body.
[0091] The relationship between the aspect ratio of the original image size and the aspect ratio of the cropped size includes the following two situations: the aspect ratio of the original image size is equal to the aspect ratio of the cropped size, and the aspect ratio of the original image size is not equal to the aspect ratio of the cropped size. Specifically, the aspect ratio of the original image size is not equal to the aspect ratio of the cropped size, including the following two situations: the aspect ratio of the original image size is greater than the aspect ratio of the cropped size, and the aspect ratio of the original image size is less than the aspect ratio of the cropped size. In both situations, the solutions for adjusting the original image size are as follows:
[0092] When the aspect ratio of the original image size is greater than the aspect ratio of the cropped size, the width of the original image size is adjusted based on the height of the original image size and the aspect ratio of the cropped size, so that the aspect ratio of the adjusted original image size is consistent with the aspect ratio of the cropped size.
[0093] When the aspect ratio of the original image size is smaller than that of the cropped size, the height of the original image size is adjusted based on the width of the original image size and the aspect ratio of the cropped size, so that the aspect ratio of the adjusted original image size is consistent with that of the cropped size.
[0094] Combine Figure 5-1 and Figure 5-2 The schematic diagram shown illustrates a solution provided by an embodiment of the present application for determining the cropping position based on the original image size, the cropping size and the center point of the connected area. Figure 5-1 The image to be cropped has its width and height denoted as w and h respectively. If the image to be cropped contains a face, a rectangular frame ( Figure 5-1 The dotted box in the image) Figure 5-1 Assume that the width and height corresponding to the crop size are represented as w' and h' respectively. Figure 5-1 As shown, w / h>w' / h', adjust the width of the original image size according to the aspect ratio of the original image size and the crop size, that is, fix the h side and adjust the w side. The adjusted original image width w1=hw' / h', and the adjusted w1 / h=w' / h'. The cropping position of the cropped image is determined according to w1, h, and the center point of the connected area. The image corresponding to the cropping position is Figure 5-2 As shown, the image body containing the face representation and part of the background area near the image body.
[0095] On this basis, after the size of the original image is adjusted, the adjusted original image is scaled proportionally by h / h' to obtain a cropped image with a width and height of w'h'. When w / h < w' / h', the height of the original image is adjusted according to the width of the original image size and the aspect ratio of the cropped size, that is, the w side is fixed and the h side is adjusted. The height h1 of the adjusted original image is h1 = wh' / w', and the adjusted w / h1 = w' / h'. The cropping position of the cropped image is determined according to w, h1, and the center point of the connected region. After the size of the original image is adjusted, the adjusted original image is scaled proportionally by w / w' to obtain a cropped image with a width and height of w'h'. Assuming that the aspect ratio corresponding to the original image size is equal to the aspect ratio corresponding to the cropped size, that is, w / h = w' / h', then there is no need to adjust the original image size, and the cropping position of the cropped image is determined according to the original image size and the center point of the connected region.
[0096] After obtaining the cropping position of the cropped image according to the above embodiments, an embodiment of the present application further provides a solution for obtaining a cropped image. The cropped image containing at least one image subject can be obtained by cropping the to-be-cropped image according to the cropping position, and can be carried out in the following manner:
[0097] D1. Crop the to-be-cropped image according to the cropping position;
[0098] D2. Determine the ratio of the aspect ratio corresponding to the original image size or the adjusted original image size to the aspect ratio corresponding to the cropped size, and proportionally adjust the image obtained by cropping the to-be-cropped image according to the cropping position to obtain a cropped image.
[0099] When the aspect ratio corresponding to the original image size or the adjusted original image size is equal to the aspect ratio corresponding to the cropped size, determine the first ratio of the two aspect ratios. Obtain the first image obtained after cropping the aforementioned to-be-cropped image using the cropping position, and proportionally adjust the width and height of the first image by this first ratio to obtain a cropped image.
[0100] The example is as follows: Assume that the aspect ratio corresponding to the original image size is equal to the aspect ratio corresponding to the cropped size, that is, w / h = w' / h', and the first ratio p = w / w'. When p > 1, the first image obtained using the cropping position is reduced to 1 / p of the first image. When p < 1, the first image obtained using the cropping position is enlarged by p times.
[0101] The cropping position determined by this solution can effectively avoid the problem of partial cropping of a single image subject, which is beneficial to improving the integrity of the image subject in the cropped image, and further improving the accuracy of the cropping position of the cropped image.
[0102] After obtaining the cropped image according to the solution provided in the above embodiment, in one embodiment of the present application, a second image can also be generated based on the cropped image, where the layer where the cropped image is located is one of the layers, and the second image includes at least two layers.
[0103] This solution involves adding additional layers to a cropped image to generate a second image. This second image can be an image with elements such as a search box or logo added. This second image is a secondary creation based on the cropped image and can be a poster or advertisement with other design elements added, allowing for advertising and user acquisition.
[0104] In one embodiment of the present application, in addition to the layer where the cropped image is located, the second image may also include a fixed layer and / or a non-fixed layer. Taking the cropped image as a video cover image as an example, the second image is a picture formed by adding a search box, a platform logo, and a drama title logo elements to the cropped image. Among them, the search box and the platform logo are in a fixed position in the layer where they are located, that is, the size and position of these elements are fixed, therefore, such elements are called fixed layers, and the position and size of the drama title logo can be adjusted, therefore, such elements are called non-fixed layers. The second image may include at least two layers, one of which is the layer where the cropped image is located, in addition to which, fixed layers and / or non-fixed layers are also included.
[0105] When the second image includes a fixed layer in addition to the layer where the cropped image is located, in one embodiment of the present application, generating the second image based on the cropped image can be performed in the following manner, including:
[0106] E1, obtain the image of the fixed layer and the main area of the cropped image;
[0107] E2, uses the area outside the main area of the image as the placement location of the image of the fixed layer;
[0108] E3, generating a second image based on the image of the fixed layer, the placement position of the image of the fixed layer, and the cropped image.
[0109] To enhance the user's visual experience, the image corresponding to the fixed layer is preferably placed in an area that does not obstruct the main image of the cropped image. Therefore, the area outside the main image area of the cropped image is used as the placement area for the image of the fixed layer. In other words, the image of the fixed layer is placed in an area outside the main image area. The image of the fixed layer is placed in the determined placement position for the image of the fixed layer, and the image of the fixed layer placed in the placement position is fused with the cropped image to form a second image.
[0110] Figure 6This is a schematic diagram of the interface of the second image provided for an embodiment of the present application. In this diagram, the image of the fixed layer is the search box and the platform logo, and the main body of the cropped image is a human face.
[0111] Figure 6 The size of the platform logo shown can be set to 180px*52px and placed in the upper right corner of the second picture. A certain distance can be left between the upper boundary of the platform logo and the upper boundary of the second picture, such as 24px. A certain distance can also be left between the right boundary of the platform logo and the right boundary of the second picture, such as 10px. The size of the search box can be set to 702px wide and 70px high. The font in the search box can be set to bold. The font size of the search font in the search box can also be set, such as 34px. The pictures in the fixed layer have no intersection with the main body of the picture in the cropped picture, such as Figure 6 As shown, the search box and the platform logo do not block the face area in the cropped image.
[0112] When the second image includes a non-fixed layer in addition to the layer where the cropped image is located, in one embodiment of the present application, generating the second image based on the cropped image can be performed in the following manner, including:
[0113] F1, obtain the image of the non-fixed layer, the preset size range of the image of the non-fixed layer, the size of the non-fixed layer, and the main image area of the image to be cropped;
[0114] F2, determining the size of the image in the non-fixed layer based on the relationship between the size of the non-fixed layer and the preset size range of the image in the non-fixed layer;
[0115] F3, divides the non-fixed layer into multiple placement areas according to the size of the images in the non-fixed layer;
[0116] F4: The placement area corresponding to the smallest intersection area between the multiple placement areas and the main area of the image is used as the placement position of the image of the non-fixed layer;
[0117] F5 generates a second image based on the image of the non-fixed layer, the placement position, and the cropped image.
[0118] The preset threshold range of the width and height corresponding to the image size of the non-fixed layer is w0 and h0. Assuming that the width and height of the non-fixed layer are represented by w1 and h1 respectively, taking the image of the drama logo as an example of the non-fixed layer, the position of the drama logo is non-fixed, and the size of the drama logo is not fixed, that is, the position and size of the image of the non-fixed layer are adjustable. The embodiments of the present application can determine the size of the image of the non-fixed layer in the following manner: when w0 / h0 > w1 / h1, fix the h1 side, and adjust the width of the non-fixed layer to w1' = w0 * h1 / h0, then the size of the drama logo is (w0 * h1 / h0, h1); when w0 / h0 < w1 / h1, fix the w1 side, and adjust the height of the non-fixed layer to h1' = w1 * h0 / w0, then the size of the drama logo is (w1, w1 * h0 / w0).
[0119] The non-fixed layer is divided into multiple placeable areas according to the size of the image of the non-fixed layer. Since the size of the non-fixed layer is smaller than the size of the fixed layer, therefore, according to the preset division method, such as moving the image of the non-fixed layer as a fixed size pixel by pixel in the non-fixed layer area, and for each pixel movement, a new placeable area can be obtained.
[0120] Taking the image of the non-fixed layer as the drama logo as an example, traverse the drama logo in the placeable areas, obtain the intersection area with the main image area in the cropped image, that is, calculate the overlapping area between the placeable position and the main image area, and use the placeable area corresponding to the smallest overlapping area between the placeable position and the main image area in the cropped image as the placement position of the image in the non-fixed layer, where the smallest overlapping area can be 0.
[0121] Place the image of the non-fixed layer at the determined placement position of the image of the non-fixed layer, and perform image fusion and other processing on the image of the non-fixed layer placed at the placement position and the cropped image to form a second image.
[0122] When determining the placement position of the image of the non-fixed layer from multiple placeable areas, in addition to the above solution, an embodiment of the present application also provides the following solution:
[0123] F6, when there are multiple placeable areas corresponding to the case of the smallest intersection area, obtain the pixel values of the multiple placeable areas corresponding to the smallest intersection area; use the placeable area with the smallest pixel change among them as the placement position of the image of the non-fixed layer.
[0124] If the intersection area is the smallest, there are multiple corresponding placement areas. Then, if these intersection areas are all A, A can be 0, and the solution provided in the above embodiment cannot accurately determine the placement position of the picture of the non-fixed layer. In order to further accurately locate the placement position of the picture of the non-fixed layer, the embodiment of the present application selects the area with the lowest energy value in the placement area corresponding to the lowest intersection area, that is, the area with the smallest change in pixel value in the placement area, and also selects the area with the smallest change in background grayscale. Placing the picture of the non-fixed layer in this placement position can highlight the picture of the non-fixed layer to the greatest extent and enhance the user's visual experience.
[0125] like Figure 6 As shown, the drama title logo is a picture of a non-fixed layer. The picture of the non-fixed layer is placed outside the main area of the picture without blocking the main body of the picture. In addition, the background color of the picture of the non-fixed layer does not change much compared to the background color of the cropped picture, which is conducive to improving the user's visual experience.
[0126] Based on the same principle as the method provided in the embodiment of the present application, the embodiment of the present application also provides a picture cropping device 60, which can implement the picture cropping solution executed by the server side, and its structural diagram is shown as follows: Figure 7 As shown, the apparatus may include: an acquisition module 610, a subject detection module 620, and a cropping module 630, wherein:
[0127] An acquisition module 610 is used to acquire the image to be cropped and the cropping size;
[0128] The subject detection module 620 is used to detect the subject of the image to be cropped and obtain the center point of the connected area covering at least one subject in the image to be cropped;
[0129] The cropping module 630 is configured to crop the image to be cropped based on the center point of the connected area and the cropping size to obtain a cropped image containing at least one image body.
[0130] The image cropping device provided in the present application determines the width and height of the cropping frame according to the cropping size, and obtains a cropped image containing at least one image body based on the center of the connected area and the cropping size. The cropped image can display the main content of the image to be cropped, thereby improving the accuracy of image cropping. Moreover, since the cropping method is based on the image body, it can avoid the situation where any image body in the image to be cropped is partially intercepted, thereby ensuring that the image bodies in the cropped image are all complete image bodies.
[0131] In one embodiment of the present application, the image subject includes a face, and the subject detection module 620 is specifically configured to:
[0132] Perform face detection on the cropped image to obtain a binary feature map of the face area;
[0133] If the binary face region feature map is valid, a connected region covering at least one face in the image to be cropped is determined based on the binary face region feature map, and a center point of the connected region is determined.
[0134] In one embodiment of the present application, when the face region feature binary map is invalid, the subject detection module 620 is further configured to:
[0135] Perform saliency detection on the cropped image to obtain a binary map of saliency features;
[0136] A connected region covering at least one salient region in the image to be cropped is obtained based on the salient feature binary map, and a center point of the connected region is determined.
[0137] In one embodiment of the present application, the subject detection module 620 is further configured to:
[0138] Determine the coverage area of each individual face in the image to be cropped based on the face region feature binary map;
[0139] The coverage area of each individual face is expanded to obtain a connected area covering at least one face in the image to be cropped.
[0140] In one embodiment of the present application, the subject detection module 620 is further configured to:
[0141] Determining at least one salient region in the image to be cropped according to the salient feature binary map;
[0142] Dilation processing is performed on at least one salient region to obtain a connected region covering the at least one salient region in the image to be cropped.
[0143] In one embodiment of the present application, the cropping module 630 is specifically configured to:
[0144] Get the original size of the image to be cropped;
[0145] Determine the cropping position of the cropped image based on the relationship between the original image size and the cropping size, as well as the center point of the connected area;
[0146] The image to be cropped is cropped according to the cropping position to obtain a cropped image containing at least one image body.
[0147] In one embodiment of the present application, the cropping module 630 includes a cropping position determining unit, which is configured to:
[0148] When the aspect ratio of the original image size is greater than the aspect ratio of the cropped image size, the width of the original image size is adjusted based on the height of the original image size and the aspect ratio of the cropped image size, so that the aspect ratio of the adjusted original image size is consistent with the aspect ratio of the cropped image size. The cropping position of the cropped image is determined based on the adjusted original image size and the center point of the connected area.
[0149] When the aspect ratio of the original image size is smaller than the aspect ratio of the cropped image size, the height of the original image size is adjusted based on the width of the original image size and the aspect ratio of the cropped image size, so that the aspect ratio of the adjusted original image size is consistent with the aspect ratio of the cropped image size. The cropping position of the cropped image is determined based on the adjusted original image size and the center point of the connected area.
[0150] When the aspect ratio corresponding to the original image size is consistent with the aspect ratio corresponding to the cropped size, the cropping position of the cropped image is determined according to the original image size and the center point of the connected area.
[0151] In one embodiment of the present application, the cropping position determining unit is further configured to:
[0152] Crop the image to be cropped according to the cropping position;
[0153] The ratio of the aspect ratio corresponding to the original image size or the adjusted original image size to the aspect ratio corresponding to the cropping size is determined, and the image after cropping the image to be cropped according to the cropping position is proportionally adjusted to obtain a cropped image.
[0154] In one embodiment of the present application, the image cropping device 60 further includes a second image generating module configured to:
[0155] A second image is generated based on the cropped image, where the second image includes at least two layers, and the layer where the cropped image is located is one of the layers.
[0156] In one embodiment of the present application, when the second image further includes a fixed layer, the second image generation module is configured to:
[0157] Get the image of the fixed layer and the main area of the cropped image;
[0158] The area outside the main area of the picture is used as the placement position of the picture of the fixed layer;
[0159] A second image is generated based on the image of the fixed layer, the placement position, and the cropped image.
[0160] In one embodiment of the present application, when the second image further includes a fixed layer, the second image generation module is configured to:
[0161] Obtaining a picture of a non-fixed layer, a preset size range of the picture of the non-fixed layer, the size of the non-fixed layer, and a main area of the picture to be cropped;
[0162] Determine the size of the image in the non-fixed layer according to the relationship between the size of the non-fixed layer and the preset size range;
[0163] Divide the non-fixed layer into multiple placement areas according to the size of the images in the non-fixed layer;
[0164] The placement area corresponding to the minimum intersection area between the plurality of placement areas and the main area of the picture is used as the placement position of the picture of the non-fixed layer;
[0165] A second image is generated based on the image of the non-fixed layer, the placement position, and the cropping of the image.
[0166] In one embodiment of the present application, the second image generation module is further configured to:
[0167] When the minimum intersection area corresponds to multiple placement areas, the pixel values of the multiple placement areas are obtained, and the placement area with the smallest pixel value change is used as the placement position of the image of the non-fixed layer.
[0168] The picture cropping device of the embodiment of the present application can execute the picture cropping method provided by the embodiment of the present application, and its implementation principle is similar. The actions performed by each module and unit in the picture cropping device in each embodiment of the present application correspond to the steps in the picture cropping method in each embodiment of the present application. For the detailed functional description of each module of the picture cropping device, please refer to the description of the corresponding picture cropping method shown in the previous text, and will not be repeated here.
[0169] Based on the same principle as the method shown in the embodiments of the present application, an electronic device is also provided in the embodiments of the present application, which may include but is not limited to: a processor and a memory; a memory for storing a computer program; a processor for executing the image cropping method shown in any embodiment of the present application by calling a computer program. The image cropping method provided in the present application determines the width and height of the cropping frame according to the cropping size, and obtains a cropped image containing at least one image body based on the center of the connected area and the cropping size. The cropped image can show the main content of the image to be cropped and improve the accuracy of image cropping. Moreover, since the cropping method is based on the image body, it can avoid the situation where any image body in the image to be cropped is partially intercepted, ensuring that the image bodies in the cropped image are all complete image bodies.
[0170] In one embodiment of the present application, an electronic device is provided, such as Figure 8 As shown, Figure 8 The electronic device 4000 shown may be a server, including a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, for example, via a bus 4002. In one embodiment of the present application, the electronic device 4000 may further include a transceiver 4004. It should be noted that in actual applications, there is not limited to one transceiver 4004, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.
[0171] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0172] Bus 4002 may include a path for transmitting information between the above components. Bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. Bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0173] The memory 4003 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these.
[0174] The memory 4003 is used to store application code for executing the solution of the present application, and the execution is controlled by the processor 4001. The processor 4001 is used to execute the application code stored in the memory 4003 to implement the content shown in the above method embodiment.
[0175] Among them, the electronic device can also be a terminal device, Figure 8 The electronic device shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.
[0176] Among them, the image cropping method provided by this application can also be implemented through cloud computing. Cloud computing refers to the delivery and use mode of IT infrastructure, which means obtaining the required resources through the network in an on-demand and easily scalable manner; in a broad sense, cloud computing refers to the delivery and use mode of services, which means obtaining the required services through the network in an on-demand and easily scalable manner. This service can be related to IT and software, the Internet, or other services. Cloud computing is the product of the development and integration of traditional computer and network technologies such as grid computing, distributed computing, parallel computing, utility computing, network storage technologies, virtualization, and load balancing.
[0177] Cloud computing has rapidly grown, driven by the internet, real-time data streams, the diversification of connected devices, and the growing demand for search services, social networks, mobile commerce, and open collaboration. Unlike previous parallel and distributed computing approaches, the emergence of cloud computing will fundamentally revolutionize the entire internet and enterprise management model.
[0178] The image cropping method provided in this application can realize automatic cropping of cropped images. This solution can also be implemented through artificial intelligence cloud services, which are generally referred to as AIaaS (AI as a Service, Chinese for "AI as a Service"). This is a current mainstream service mode of artificial intelligence platforms. Specifically, the AIaaS platform will split several common AI services and provide independent or packaged services in the cloud. This service model is similar to opening an AI theme mall: all developers can access and use one or more artificial intelligence services provided by the platform through API interfaces. Some senior developers can also use the AI framework and AI infrastructure provided by the platform to deploy and operate their own exclusive cloud artificial intelligence services. In this application, the AI framework and AI infrastructure provided by the platform can be used to implement the image cropping method provided in this application.
[0179] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding contents of the aforementioned method embodiment.
[0180] It should be understood that although the steps in the flowcharts of the accompanying drawings are shown in sequence as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the flowcharts of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0181] The computer-readable storage medium provided in the embodiment of the present application can be, for example, but not limited to, a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. A more specific example of a computer-readable storage medium can include, but is not limited to, an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by an instruction execution system, device, or device or used in combination with it.
[0182] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method shown in the above embodiment.
[0183] According to another aspect of the present application, a computer program product or computer program is also provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the image cropping method provided in the various implementations described above.
[0184] Computer program code for performing the operations of the present application can be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0185] The flow charts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of code contains one or more executable instructions for realizing the prescribed logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart, can be implemented by a dedicated hardware-based system that performs the prescribed function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0186] The modules described in the embodiments of the present application may be implemented in software or hardware. The name of a module does not necessarily limit the module itself. For example, the acquisition module may also be described as a "module for acquiring an image to be cropped and cropping size."
[0187] The above description is merely a preferred embodiment of the present application and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but also encompasses other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the above-mentioned disclosed concepts. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A method for cropping an image, characterized in that: include: Get the image to be cropped and the cropping size; Performing image subject detection on the image to be cropped to obtain a center point of a connected area covering at least one image subject in the image to be cropped; Cropping the image to be cropped based on the center point of the connected area and the cropping size to obtain a cropped image including the at least one image body; Obtaining a picture of a non-fixed layer to be synthesized, a preset size range of the picture of the non-fixed layer, a size of the non-fixed layer, and a main picture area of the cropped picture; Determining the size of the image of the non-fixed layer according to the relationship between the size of the non-fixed layer and the preset size range; Determining, according to the size of the image of the non-fixed layer and the size of the non-fixed layer, a plurality of placement areas of the image of the non-fixed layer in the non-fixed layer; Determine the intersection area of each of the placement areas and the image main area; When there is only one corresponding placement area with the smallest cross-area, the placement area with the smallest cross-area is determined as the placement position of the image of the non-fixed layer; When there are at least two placement areas with the smallest corresponding intersection area, determining a pixel value change in each of the at least two placement areas, and determining the placement area with the smallest corresponding pixel value change as the placement position of the image of the non-fixed layer; The cropped image and the image of the non-fixed layer are respectively regarded as a layer, and a second image is generated based on the image of the non-fixed layer and its placement position, and the cropped image.
2. The method according to claim 1, characterized in that The image subject includes a face, and the performing image subject detection on the image to be cropped to obtain a center point of a connected area covering at least one image subject in the image to be cropped includes: Performing face detection on the image to be cropped to obtain a binary feature map of the face area; If the face region feature binary map is valid, a connected region covering at least one face in the image to be cropped is determined based on the face region feature binary map, and a center point of the connected region is determined.
3. The method according to claim 2, characterized in that If the face region feature binary map is invalid, performing image subject detection on the image to be cropped to obtain a center point of a connected area covering at least one image subject in the image to be cropped further includes: Performing saliency detection on the image to be cropped to obtain a saliency feature binary map; A connected region covering at least one salient region in the image to be cropped is obtained based on the salient feature binary map, and a center point of the connected region is determined.
4. The method according to claim 2, characterized in that The determining, based on the face region feature binary map, of a connected region covering at least one face in the image to be cropped includes: Determining the coverage area of each individual face in the image to be cropped based on the face region feature binary map; The coverage area of each of the single faces is expanded to obtain a connected area covering at least one face in the image to be cropped.
5. The method according to claim 3, characterized in that The obtaining, based on the salient feature binary map, of a connected region covering at least one salient region in the image to be cropped includes: Determining at least one salient region in the image to be cropped according to the salient feature binary map; Dilation processing is performed on the at least one salient region to obtain a connected region covering the at least one salient region in the image to be cropped.
6. The method according to claim 1, characterized in that The step of cropping the image to be cropped based on the center point of the connected area and the cropping size to obtain a cropped image containing the at least one image body includes: Obtaining the original size of the image to be cropped; Determining a cropping position of the cropped image according to a relationship between the original image size and the cropping size, and a center point of the connected area; The image to be cropped is cropped according to the cropping position to obtain a cropped image including the at least one image body.
7. The method according to claim 6, characterized in that The original image size and the cropping size include width and height, and determining the cropping position of the cropped image according to the relationship between the original image size and the cropping size and the center point of the connected area includes: When the aspect ratio of the original image size is greater than the aspect ratio of the cropped image size, the width of the original image size is adjusted based on the height of the original image size and the aspect ratio of the cropped image size, so that the aspect ratio of the adjusted original image size is consistent with the aspect ratio of the cropped image size. The cropping position of the cropped image is determined based on the adjusted original image size and the center point of the connected area. When the aspect ratio of the original image size is smaller than the aspect ratio of the cropped image size, the height of the original image size is adjusted based on the width of the original image size and the aspect ratio of the cropped image size, so that the aspect ratio of the adjusted original image size is consistent with the aspect ratio of the cropped image size. The cropping position of the cropped image is determined based on the adjusted original image size and the center point of the connected area. When the aspect ratio corresponding to the original image size is consistent with the aspect ratio corresponding to the cropped image size, the cropping position of the cropped image is determined according to the original image size and the center point of the connected area.
8. The method according to claim 7, characterized in that The step of cropping the image to be cropped according to the cropping position to obtain a cropped image including the at least one image body includes: Cropping the image to be cropped according to the cropping position; Determine the ratio of the aspect ratio corresponding to the original image size or the adjusted original image size to the aspect ratio corresponding to the cropping size, and perform proportional adjustment on the image after cropping the image to be cropped according to the cropping position to obtain a cropped image.
9. A picture cutting device, characterized in that: include: The acquisition module is used to obtain the image to be cropped and the cropping size; a subject detection module, configured to perform subject detection on the image to be cropped, and obtain a center point of a connected area covering at least one subject in the image to be cropped; a cropping module, configured to crop the image to be cropped based on the center point of the connected area and the cropping size to obtain a cropped image containing the at least one image body; A second image generation module is used to obtain an image of a non-fixed layer to be synthesized, a preset size range of the image of the non-fixed layer, a size of the non-fixed layer, and an image main area of the cropped image; Determining the size of the image of the non-fixed layer according to the relationship between the size of the non-fixed layer and the preset size range; Determining, according to the size of the image of the non-fixed layer and the size of the non-fixed layer, a plurality of placement areas of the image of the non-fixed layer in the non-fixed layer; Determine the intersection area of each of the placement areas and the image main area; When there is only one corresponding placement area with the smallest cross-area, the placement area with the smallest cross-area is determined as the placement position of the image of the non-fixed layer; When there are at least two placement areas with the smallest corresponding intersection area, determining a pixel value change in each of the at least two placement areas, and determining the placement area with the smallest corresponding pixel value change as the placement position of the image of the non-fixed layer; The cropped image and the image of the non-fixed layer are respectively regarded as a layer, and a second image is generated based on the image of the non-fixed layer and its placement position, and the cropped image.
10. The device according to claim 9, characterized in that The subject of the image includes a face, and the subject detection module is specifically used to: Performing face detection on the image to be cropped to obtain a binary feature map of the face area; If the face region feature binary map is valid, a connected region covering at least one face in the image to be cropped is determined based on the face region feature binary map, and a center point of the connected region is determined.
11. The device according to claim 10, characterized in that If the face region feature binary map is invalid, the subject detection module is further configured to: Performing saliency detection on the image to be cropped to obtain a saliency feature binary map; A connected region covering at least one salient region in the image to be cropped is obtained based on the salient feature binary map, and a center point of the connected region is determined.
12. The device according to claim 10, characterized in that The subject detection module is further configured to: Determining the coverage area of each individual face in the image to be cropped based on the face region feature binary map; The coverage area of each of the single faces is expanded to obtain a connected area covering at least one face in the image to be cropped.
13. The device according to claim 11, characterized in that The subject detection module is further configured to: Determining at least one salient region in the image to be cropped according to the salient feature binary map; Dilation processing is performed on the at least one salient region to obtain a connected region covering the at least one salient region in the image to be cropped.
14. The device according to claim 10, characterized in that The cutting module is specifically used for: Obtaining the original size of the image to be cropped; Determining a cropping position of the cropped image according to a relationship between the original image size and the cropping size, and a center point of the connected area; The image to be cropped is cropped according to the cropping position to obtain a cropped image including the at least one image body.
15. The device according to claim 14, characterized in that The original image size and the cropping size include width and height. The cropping module includes a cropping position determining unit, and the cropping position determining unit is configured to: When the aspect ratio of the original image size is greater than the aspect ratio of the cropped image size, the width of the original image size is adjusted based on the height of the original image size and the aspect ratio of the cropped image size, so that the aspect ratio of the adjusted original image size is consistent with the aspect ratio of the cropped image size. The cropping position of the cropped image is determined based on the adjusted original image size and the center point of the connected area. When the aspect ratio of the original image size is smaller than the aspect ratio of the cropped image size, the height of the original image size is adjusted based on the width of the original image size and the aspect ratio of the cropped image size, so that the aspect ratio of the adjusted original image size is consistent with the aspect ratio of the cropped image size. The cropping position of the cropped image is determined based on the adjusted original image size and the center point of the connected area. When the aspect ratio corresponding to the original image size is consistent with the aspect ratio corresponding to the cropped image size, the cropping position of the cropped image is determined according to the original image size and the center point of the connected area.
16. The device according to claim 15, characterized in that The cropping position determining unit is further configured to: Cropping the image to be cropped according to the cropping position; Determine the ratio of the aspect ratio corresponding to the original image size or the adjusted original image size to the aspect ratio corresponding to the cropping size, and perform proportional adjustment on the image after cropping the image to be cropped according to the cropping position to obtain a cropped image.
17. An electronic device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 8 when executing the program.
18. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Image area cutting method and device, storage medium and electronic device
CN110349082A