Image extraction method and device, electronic equipment and storage medium
By obtaining touch position information and detecting object borders in mobile terminal devices, combined with a variety of image segmentation models and feature processing technologies, the problem of difficulty in extracting insignificant objects in image matting by mobile terminal devices is solved, and image processing is improved. capabilities and application scenarios.
Patent Information
- Application Number
- CN202310185472.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-21
- Publication Date
- 2024-08-23
AI Technical Summary
When mobile terminal devices perform image cutout, especially for pictures where the main target is not obvious, there is a problem of difficulty in extraction. The existing one-click cutout function is limited and cannot effectively handle objects whose pixel ratio is less than a certain threshold.
By obtaining the touch position information, detecting the frame information of the object, and using a variety of image segmentation models to segment the image to be extracted according to the pixel ratio, including the first image segmentation model and the second image segmentation model, combined with feature extraction and fusion structure, The fused feature map is processed to obtain the target image.
It improves the extraction capability of electronic devices in image processing, can effectively process objects with a pixel ratio within a certain range, expands the application scenarios of image extraction, and enhances the universality and accuracy of image processing.
Smart Images

Figure CN118537356A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of display technology, and in particular to an image extraction method and device, an electronic device, and a storage medium. Background Art
[0002] In computers, the magic wand quick selection tool or pen tool of image processing (Adobe Photoshop, PS) software is generally used for cutout operations. On mobile terminals such as mobile phones, due to the limitations of the operation mode, the manual and refined cutout process is obviously not convenient enough. Instead, the software intelligent processing algorithm is used, which can automatically distinguish between the image and the background. For example, through the one-key cutout tool, the main target in the image can be extracted by long pressing. However, this one-key cutout function is only applicable to pictures with prominent main targets, i.e., objects, and there is a problem of difficulty in extraction for images where the main target is not prominent. Summary of the invention
[0003] In order to overcome the problems existing in the related art, the present disclosure provides an image extraction method and device, an electronic device, and a storage medium, which can improve the image processing capability of the electronic device.
[0004] According to a first aspect of an embodiment of the present disclosure, there is provided an image extraction method, comprising at least:
[0005] Acquire touch position information of the image to be extracted;
[0006] Detecting an object associated with the touch position information in the image to be extracted to obtain frame information of the object;
[0007] When the pixel ratio of the object determined according to the border information is greater than or equal to a first threshold and less than or equal to a second threshold, the object in the image to be extracted is segmented using a first image segmentation model to obtain a target image.
[0008] In some embodiments, the method further comprises:
[0009] When the pixel ratio of the object is greater than or equal to a third threshold, segmenting the object in the image to be extracted using a second image segmentation model to obtain the target image;
[0010] When the pixel proportion of the object is greater than the second threshold and less than the third threshold, the target image is obtained based on the first pixel result obtained by segmentation of the first image segmentation model and the second pixel result obtained by segmentation of the second image segmentation model.
[0011] In some embodiments, obtaining the target image based on the first pixel result obtained by segmentation of the first image segmentation model and the second pixel result obtained by segmentation of the second image segmentation model includes:
[0012] Averaging the pixel values in the first pixel result and the pixel values in the second pixel result to obtain an average pixel result;
[0013] The target image is constructed based on the average pixel results.
[0014] In some embodiments, the step of using a first image segmentation model to segment the object in the image to be extracted to obtain a target image includes:
[0015] Extracting features from the image to be extracted by using the feature extraction structure of the first image segmentation model;
[0016] The extracted features are fused by the feature fusion structure of the first image segmentation model to obtain a fused feature map;
[0017] The fused feature map is processed through the side output structure of the first image segmentation model to obtain the target image.
[0018] In some embodiments, the processing of the fused feature map through the side output structure of the first image segmentation model to obtain the target image includes:
[0019] Processing the fused feature map through the first computing module of the side output structure to obtain output feature maps of different feature channels;
[0020] The output feature maps of different feature channels are spliced by the splicing module of the side output structure to obtain a spliced feature map;
[0021] The splicing feature map is processed by the second computing module of the side output structure to obtain the target image.
[0022] In some embodiments, the method further comprises:
[0023] Acquire a detection target based on the touch position information;
[0024] In the case where there are multiple detection targets, the object is obtained based on the multiple detection targets.
[0025] In some embodiments, obtaining the object based on the plurality of detection targets comprises:
[0026] In a case where the pixel distance between at least two of the plurality of detection targets is less than a distance threshold, treating the at least two detection targets as one object;
[0027] In the case that the pixel distance between at least two of the multiple detection targets is greater than or equal to the distance threshold, each of the at least two detection targets is regarded as an object.
[0028] In some embodiments, the method further comprises:
[0029] Determine the area of the object according to the border pixel width and the border pixel height in the border information;
[0030] Based on the ratio of the area of the object to the pixel area of the image to be extracted, the pixel ratio of the object is obtained.
[0031] In some embodiments, the border information includes: the minimum horizontal coordinate of the object in the pixel coordinate system, the minimum vertical coordinate of the object in the pixel coordinate system, the pixel width of the border of the object, and the pixel height of the border of the object.
[0032] In some embodiments, the method further comprises:
[0033] Acquire a pasted image having the object from the target image, wherein the background of the pasted image is transparent;
[0034] Paste the paste image into the specified image.
[0035] According to a second aspect of an embodiment of the present disclosure, there is provided an image capturing device, comprising at least:
[0036] An acquisition module is configured to acquire touch position information of the image to be extracted;
[0037] A detection module, configured to detect an object associated with the touch position information in the image to be extracted, and obtain frame information of the object;
[0038] The first segmentation module is configured to use the first image segmentation model to segment the object in the image to be extracted to obtain a target image when the pixel ratio of the object determined according to the border information is greater than or equal to a first threshold and less than or equal to a second threshold.
[0039] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, comprising at least:
[0040] processor;
[0041] a memory for storing processor-executable instructions;
[0042] Wherein, the processor is configured to execute the image extraction method as described in the first aspect above.
[0043] According to a fourth aspect of an embodiment of the present disclosure, there is provided a storage medium, including:
[0044] When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the image extraction method in the first aspect as described above.
[0045] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0046] In the disclosed embodiment, the electronic device obtains the touch position information of the image to be extracted; detects the object associated with the touch position information in the image to be extracted to obtain the frame information of the object; and when the pixel ratio of the object determined according to the frame information is greater than or equal to the first threshold and less than or equal to the second threshold, the first image segmentation model is used to segment the object in the image to be extracted to obtain the target image. In other words, the disclosed embodiment can separate objects whose pixel ratio is greater than or equal to the first threshold and less than or equal to the second threshold from the image to be extracted. Compared with the existing method that can only extract objects whose pixel ratio is greater than the second threshold, it not only enriches the image processing function of the electronic device and improves the extraction capability, but also expands the application scenarios of image extraction, making the image processing method universal.
[0047] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0049] Figure 1 is a schematic diagram of an image extraction scenario according to an exemplary embodiment.
[0050] Figure 2 It is a schematic diagram showing extracting an animal dog from an image extraction scene according to an exemplary embodiment.
[0051] Figure 3 It is a flowchart of an image extraction method according to an exemplary embodiment.
[0052] Figure 4 is a schematic diagram of an image to be extracted according to an exemplary embodiment.
[0053] Figure 5 It is a schematic diagram of extracting an elephant in an image extraction scene according to an exemplary embodiment.
[0054] Figure 6 is a schematic structural diagram of an image capturing device according to an exemplary embodiment.
[0055] Figure 7 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0056] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0057] In related technologies, such as Figure 1 and Figure 2 As shown in the figure, if the pixel ratio of the animal dog as an object in the photo is greater than the third threshold (the third threshold is greater than the second threshold), it can be regarded as a significant object. Therefore, the animal dog in the photo can be extracted through the one-key cutout function corresponding to the one-key cutout tool on the mobile phone. However, if the pixel ratio of the object is less than or equal to the second threshold and greater than or equal to the first threshold, that is, the object is not significant and is a small target, there is a problem of difficulty in image extraction due to the small pixels of the object.
[0058] Based on this, the present disclosure proposes an image extraction method. Figure 3 As shown, the image extraction method comprises the following steps:
[0059] S101, obtaining touch position information of touching an image to be extracted;
[0060] S102, detecting an object associated with the touch position information in the image to be extracted, and obtaining frame information of the object;
[0061] S103. When the pixel ratio of the object determined according to the border information is greater than or equal to a first threshold and less than or equal to a second threshold, use a first image segmentation model to segment the object in the image to be extracted to obtain a target image.
[0062] In the disclosed embodiment, the image extraction method is applied in performing image extraction, i.e., the cutout function. For example, in the cutout mode, i.e., when entering the cutout page, the target image is obtained by the image extraction method, and then the target image can be copied or dragged to implement the cutout function.
[0063] The above-mentioned image extraction method can be applied to electronic devices. The electronic device may include a mobile device, a wearable device or a camera. Among them, the mobile device includes a smart phone, a tablet computer or a laptop computer; the wearable device includes a smart watch or a smart bracelet, which is not limited in the embodiments of the present disclosure.
[0064] In step S101, when the image to be extracted is displayed on the cutout interface of the electronic device, the image to be extracted can be touched. In the embodiment of the present disclosure, touching the image to be extracted may include directly touching the image to be extracted with a finger or touching the image to be extracted with a stylus, which is not limited in the embodiment of the present disclosure.
[0065] The above-mentioned image to be extracted can be an image obtained by taking a photo, or an image selected from a gallery, which is not limited in the embodiment of the present disclosure. Figure 4 As shown, the elephant image can be used as the image to be extracted.
[0066] It should be noted that the resolution of the image to be extracted needs to be greater than the preset resolution. For example, the image to be extracted may be acquired by an image sensor in the range of 100 million to 200 million pixels. When the image to be extracted is acquired by an image sensor with 100 million pixels, the resolution of the image to be extracted may be 12032 x 9024; when the image to be extracted is acquired by an image sensor with 200 million pixels, the resolution of the image to be extracted may be 16320*12240.
[0067] In this way, the resolution of the image to be extracted is set to be greater than the preset resolution, so that the target image can be clearer after being enlarged when the pixel ratio of the object is less than or equal to the second threshold and greater than or equal to the first threshold.
[0068] The above-mentioned touch position information may include the coordinates of the touch point that touches the image to be extracted. Since the image to be extracted is composed of multiple pixels, the coordinates of the touch point may include pixel coordinates.
[0069] In step S102, after acquiring the touch position information, the electronic device may detect the object associated with the touch position information in the image to be extracted to obtain the frame information of the object. The object may be a person or an animal in the image to be extracted, which is not limited in the embodiment of the present disclosure. Figure 4 As shown, the image to be extracted is an elephant image, and the corresponding object may be an elephant in the elephant image.
[0070] In an embodiment of the present disclosure, before target detection, the image to be extracted can be processed to obtain a detection image, and target detection based on the touch position information on the image to be extracted to obtain the border information of the object may include: inputting the touch position information and the detection image into a detection model to obtain the border information of the object.
[0071] The above-mentioned processing of the image to be extracted to obtain the detection image may include: performing size transformation and / or color change on the image to be extracted to obtain the detection image. The detection image may include a red, green, and blue (RGB) image of 448×448 pixels, which is not limited in the embodiment of the present disclosure.
[0072] The above detection model may be any detection model that can detect an object. For example, the detection model may include a lightweight target detection model improved based on NanoDet, which is not limited in the embodiments of the present disclosure.
[0073] In the embodiment of the present disclosure, the frame information of the object may include the coordinates of any point on the target frame of the object, and may also include the coordinates of the center point of the object, which is not limited in the embodiment of the present disclosure.
[0074] In some embodiments, the border information includes: the minimum horizontal coordinate of the object in the pixel coordinate system, the minimum vertical coordinate of the object in the pixel coordinate system, the pixel width of the border of the object, and the pixel height of the border of the object.
[0075] In the disclosed embodiment, a pixel coordinate system is constructed on the image to be extracted, and the above-mentioned minimum horizontal coordinate may be the difference between the minimum value of the horizontal system of the object in the pixel coordinate system and the preset pixel margin; the minimum vertical coordinate may be the difference between the minimum value of the vertical system of the object in the pixel coordinate system and the preset pixel margin.
[0076] For example, the minimum horizontal coordinate X can be obtained by formula (1), and the minimum vertical coordinate Y can be obtained by formula (2). min , the preset pixel margin is represented by t, and the minimum value of the vertical system is represented by y min .
[0077] X=x min -t (1)
[0078]
[0079] In the embodiment of the present disclosure, the pixel width of the border of the object may be obtained according to a preset pixel margin, a minimum horizontal value and a maximum horizontal value of the object in the pixel coordinate system.
[0080] For example, the pixel width of the object's border w can be obtained by formula (3): tar Among them, the maximum value of the horizontal system is represented by x max .
[0081] w tar =x max -x min +2t (3)
[0082] In the embodiment of the present disclosure, the pixel height of the border of the above-mentioned object is obtained according to a preset pixel margin, a minimum vertical value and a maximum vertical value of the object in the pixel coordinate system.
[0083] For example, the pixel height of the object's border h can be obtained by formula (4): tar Among them, the maximum value of the longitudinal system is represented by y max .
[0084] h tar =y max -y min +2t (4)
[0085] In step S103, when the border information is obtained, the pixel ratio of the object can be determined based on the border information, and then the pixel ratio is compared with the first threshold and the second threshold respectively, and when the pixel ratio is less than or equal to the second threshold and greater than or equal to the first threshold, the first image segmentation model is used to segment the object in the image to be extracted to obtain the target image.
[0086] In some embodiments, the method further comprises:
[0087] Determine the pixel area of the object according to the border pixel width and the border pixel height in the border information;
[0088] Based on the ratio of the pixel area of the object to the pixel area of the image to be extracted, the pixel ratio of the object is obtained.
[0089] In the disclosed embodiment, determining the pixel area of the object according to the border pixel width and the border pixel height in the border information may include: taking the product of the border pixel width and the border pixel height as the area of the object.
[0090] For example, the pixel area s of the object can be obtained by formula (5).
[0091] s=w tar ×h tar (5)
[0092] It should be noted that the pixel area of the image to be extracted can be obtained by the pixel width and pixel height of the image to be extracted. For example, the product of the pixel width of the image to be extracted and the pixel height of the image to be extracted is used as the pixel area of the image to be extracted.
[0093] In the embodiment of the present disclosure, in the process of obtaining the pixel ratio of the object, the pixel ratio λ of the object can be obtained by formula (6).
[0094] λ=s / s0 (6)
[0095] The pixel area of the image to be extracted is represented as s0.
[0096] It should be noted that the pixel ratio of the object is between 0 and 1.
[0097] In the embodiment of the present disclosure, after obtaining the pixel ratio, if the pixel ratio is less than or equal to the second threshold and greater than or equal to the first threshold, the first image segmentation model is used to segment and obtain the target image. In other words, the image extraction method of the embodiment of the present disclosure can be applied to scenes where the object is not significant, that is, small targets are extracted, which solves the problem that electronic devices can only extract objects whose pixel ratio is greater than the third threshold, and expands the application scenarios.
[0098] The first image segmentation model is used to extract an object whose pixel ratio is less than or equal to the second threshold and greater than or equal to the first threshold, so that the object is segmented from the image to be extracted. The first image segmentation model may include a deep learning instance segmentation model improved based on the Unet model.
[0099] It should be noted that the input of the first image segmentation model is the image to be extracted and the frame information, and the output of the first image segmentation model is the target image. The target image includes a binary black and white pixel image.
[0100] In the disclosed embodiment, the electronic device obtains the touch position information of the image to be extracted; detects the object associated with the touch position information in the image to be extracted to obtain the frame information of the object; and when the pixel ratio of the object determined according to the frame information is greater than or equal to the first threshold and less than or equal to the second threshold, the first image segmentation model is used to segment the object in the image to be extracted to obtain the target image. In other words, the disclosed embodiment can separate objects whose pixel ratio is greater than or equal to the first threshold and less than or equal to the second threshold from the image to be extracted, which not only enriches the image processing function of the electronic device and improves the extraction capability, but also can expand the application scenarios of image extraction.
[0101] In some embodiments, the method further comprises:
[0102] When the pixel ratio of the object is greater than or equal to a third threshold, segmenting the object in the image to be extracted using a second image segmentation model to obtain the target image;
[0103] When the pixel proportion of the object is greater than the second threshold and less than the third threshold, the target image is obtained based on the first pixel result obtained by segmentation of the first image segmentation model and the second pixel result obtained by segmentation of the second image segmentation model.
[0104] In the disclosed embodiment, before segmentation, the electronic device not only needs to compare the pixel ratio of the object with the first threshold and the second threshold, but also needs to compare the pixel ratio of the object with the third threshold. The first threshold can be expressed as λ1; the second threshold can be expressed as λ2; the third threshold can be expressed as λ3, and 0<λ1<λ2<λ3<1.
[0105] It should be noted that the pixel ratio of an object can be expressed as λ. When λ≥λ3, the object can be defined as a large target; when λ2≤λ<λ3, the object can be defined as a medium target; when λ1≤λ<λ2, the object can be defined as a small target. It can be seen that the target extraction method of the embodiment of the present disclosure can process large targets, medium targets and small targets to obtain target images.
[0106] The input of the second image segmentation model is the image to be extracted and the border information, and the output of the second image segmentation model is the target image. For example, the second image segmentation model includes a lightweight image segmentation network SegNet model, which is not limited in the embodiments of the present disclosure.
[0107] It should be noted that when the pixel ratio of an object is less than the first threshold, the object will be ignored due to its small area. During the execution process, the electronic device segments objects whose pixel ratio is greater than or equal to the first threshold.
[0108] In the disclosed embodiment, the electronic device can segment and obtain the target image not only when the pixel ratio is greater than or equal to the first threshold and less than or equal to the second threshold, but also when the pixel ratio is greater than or equal to the third threshold and when the pixel ratio is greater than the second threshold and less than the third threshold. It can be seen that compared with the existing method that can only extract images of objects whose pixel ratio is greater than or equal to the third threshold, the image extraction method of this embodiment can extract objects of different sizes and adopts corresponding segmentation methods for objects of different sizes. In this way, the disclosed embodiment can not only expand the image extraction capability, but also improve the accuracy of image extraction.
[0109] In some embodiments, obtaining the target image based on the first pixel result obtained by segmentation of the first image segmentation model and the second pixel result obtained by segmentation of the second image segmentation model includes:
[0110] Averaging the pixel values in the first pixel result and the pixel values in the second pixel result to obtain an average pixel result;
[0111] The target image is constructed based on the average pixel results.
[0112] In the disclosed embodiment, the first pixel result may be the pixel values of multiple pixel points in the target image obtained based on the first image segmentation model; the second pixel result may be the pixel values of multiple pixel points in the target image obtained based on the second image segmentation model.
[0113] It should be noted that averaging the pixel values in the first pixel result and the pixel values in the second pixel result to obtain the average pixel result includes: obtaining the average pixel value of each pixel in the target image based on the first pixel result and the second pixel result; and forming the average pixel result based on the average pixel value of each pixel in the target image.
[0114] For example, the pixel value of the same pixel point in the image to be extracted is A in the first pixel result and B in the second pixel result, and the pixel value of the same pixel point in the corresponding average pixel result is the average value of A and B.
[0115] In the embodiment of the present disclosure, when the pixel ratio of the object is greater than the second threshold and less than the third threshold, that is, the object is a medium target, the target image is obtained based on the first pixel result obtained by segmentation of the first image segmentation model and the second pixel result obtained by segmentation of the second image segmentation model, which can improve the extraction accuracy in the case of extracting medium targets.
[0116] In some embodiments, the step of using a first image segmentation model to segment the object in the image to be extracted to obtain a target image includes:
[0117] Extracting features from the image to be extracted by using the feature extraction structure of the first image segmentation model;
[0118] The extracted features are fused by the feature fusion structure of the first image segmentation model to obtain a fused feature map;
[0119] The fused feature map is processed through the side output structure of the first image segmentation model to obtain the target image.
[0120] In the embodiment of the present disclosure, extracting features from the image to be extracted by using the feature extraction structure of the first image segmentation model may include: extracting features for objects in the image to be extracted at different scales by using multiple layers of convolution and downsampling in the feature extraction structure.
[0121] Among them, each layer of convolution uses a convolution kernel of size 3×3, the number of convolution kernels for the first two convolution operations is 16, and the number of convolution kernels for the remaining convolution operations is 32. The size of the feature map in the feature extraction structure is not changed during each convolution operation. After convolution, normalization processing and rectified linear unit (ReLU) activation function can be used for processing, and the processing result is output to downsampling. Downsampling uses the maximum pooling operation to reduce the length and width of the feature map in the feature extraction structure to 1 / 2 of the image to be extracted. In this way, the increase in computational complexity can be reduced while increasing the network depth of the first image segmentation model.
[0122] In the disclosed embodiment, the extracted features are fused through the feature fusion structure of the first image segmentation model to obtain a fused feature map, including: performing multi-layer convolution and downsampling on the extracted features through the feature fusion structure to obtain a fused feature map.
[0123] In the process of fusing the extracted features through the feature fusion structure, the convolution operation is performed after splicing with the feature layer of the feature extraction path while upsampling, so that accurate positioning can be achieved while capturing rich fusion features. Upsampling can use a bilinear interpolation method to expand the length and width of the feature map in the feature fusion structure to twice the original, so that the feature map of the current layer in the feature fusion structure is the same size as the feature map of the feature extraction path, which can be spliced.
[0124] It should be noted that the number of convolution kernels in the convolution operation in the feature fusion result is 16 in the last two convolutions, and the number of convolution kernels in the remaining convolution operations is 32. In this way, the feature extraction structure and the feature fusion structure can form a symmetrical structure.
[0125] The above-mentioned side output structure can fuse fusion feature maps of different scales to obtain rich feature output information, that is, output the target image.
[0126] In the embodiment of the present disclosure, the first image segmentation model of the electronic device adds a side output structure, and the side output result is further processed to make the image extraction of the electronic device more accurate.
[0127] In some embodiments, the processing of the fused feature map through the side output structure of the first image segmentation model to obtain the target image includes:
[0128] Processing the fused feature map through the first computing module of the side output structure to obtain output feature maps of different feature channels;
[0129] The output feature maps of different feature channels are spliced by the splicing module of the side output structure to obtain a spliced feature map;
[0130] The splicing feature map is processed by the second computing module of the side output structure to obtain the target image.
[0131] In the disclosed embodiment, the first calculation module may include: a first convolution module and a Sigmoid function calculation module. Here, in the calculation process by the first calculation module, the first calculation result can be obtained by the 1x1 convolution operation of the first convolution module, and then the first calculation result is input into the Sigmoid function calculation module to obtain the output feature map.
[0132] It should be noted that the first computing module may further include an upsampling module, through which the output feature map is upsampled to the same size as the largest output feature map.
[0133] In the disclosed embodiment, the number of feature channels of the output feature map is the same as the number of channels of the spliced feature map. For example, the output feature maps of N feature channels are spliced to obtain a spliced feature map of N feature channels.
[0134] The second computing module may include a second convolution module.
[0135] The above-mentioned processing of the spliced feature map by the second computing module of the side output structure to obtain the target image includes: processing the spliced feature map by a 1x1 convolution operation of the second convolution module to obtain the target image.
[0136] In the embodiment of the present disclosure, the first image segmentation model may be trained using a supervised learning training method, and the total training loss L of the first image segmentation model may refer to formula (7).
[0137]
[0138] Where M is the maximum number of layers in the model; l s (m) is the loss value of the output feature map of the mth layer; l o is the loss value of the final output target image, ω s (m) and ω o are the output feature map of the mth layer and the loss weights of the final output target image, respectively.
[0139] In the disclosed embodiment, the loss value of the first image segmentation model may be calculated using binary cross entropy, for example, by using formula (8).
[0140]
[0141] Among them, H and W are the number of rows and columns of pixels of the object, (r, c) is the coordinate of the pixel point, and P G (r,c) and P S (r,c) are the pixel values of the data label and the target image at the pixel point (r,c) respectively.
[0142] In some embodiments, the method further comprises:
[0143] Acquire a detection target based on the touch position information;
[0144] In the case where there are multiple detection targets, the object is obtained based on the multiple detection targets.
[0145] In the disclosed embodiment, when the touch position information represents multiple touch positions, there may be multiple detection targets. It should be noted that when the user touches an area of the image to be extracted, the area will be regarded as a detection target; when multiple areas are touched, the multiple touched areas can be regarded as multiple detection targets.
[0146] For example, if there are two animals in the image to be extracted and both are touched, the two animals can be used as two detection targets.
[0147] In the embodiment of the present disclosure, when there are multiple detection targets, objects can be obtained from the multiple detection targets based on different methods. Of course, when there is only one detection target, the detection target can be directly used as the object. It can be seen that the embodiment of the present disclosure can process one or more detection targets to obtain the final object, and can be used to obtain objects in different touch scenarios, which not only expands the application scenarios, but also improves the accuracy, and better meets the user's cutout needs.
[0148] In some embodiments, obtaining the object based on the plurality of detection targets comprises:
[0149] In a case where the pixel distance between at least two of the plurality of detection targets is less than a distance threshold, treating the at least two detection targets as one object;
[0150] In the case that the pixel distance between at least two of the multiple detection targets is greater than or equal to the distance threshold, each of the at least two detection targets is regarded as an object.
[0151] In the embodiment of the present disclosure, if the pixel distance between at least two detection targets among the multiple detection targets is less than the distance threshold, it can be indicated that at least two detection targets are connected to each other or overlap each other. In this case, at least two detection targets need to be regarded as one object, and the corresponding detection model will output the border information of one object.
[0152] It should be noted that the at least two detection targets may be obtained by touching different positions of the image to be extracted simultaneously, or by touching different positions of the image to be extracted at different times, which is not limited in the embodiments of the present disclosure.
[0153] In the embodiment of the present disclosure, if the pixel distance between at least two detection targets among the multiple detection targets is greater than or equal to the distance threshold, it can be indicated that the at least two detection targets are spaced apart from each other. In this case, each detection target needs to be output as an object, and the frame information of at least two objects will be output accordingly.
[0154] It should be noted that, in a scenario where the pixel distance between at least two detection targets among the multiple detection targets is greater than or equal to the distance threshold, the number of detection targets is the same as the number of objects.
[0155] For example, Figure 4 and Figure 5 As shown, the image to be extracted is an elephant image, and there are four detection targets in the elephant image, namely four elephants; the corresponding output objects are three, among which the two elephants on the right side of the elephant image are connected, and the two elephants on the right side will be output as one object.
[0156] In the embodiment of the present disclosure, the electronic device can output either one object or multiple objects by judging multiple detection targets. Therefore, the image extraction method of the embodiment of the present disclosure is not only applicable to the extraction of a single object, but also to the extraction of multiple objects, which can enrich the extraction scenarios and further enhance the ability of intelligent image processing.
[0157] In some embodiments, the method further comprises:
[0158] Acquire a pasted image having the object from the target image, wherein the background of the pasted image is transparent;
[0159] Paste the paste image into the specified image.
[0160] In the disclosed embodiment, in the pasting scene, after obtaining the target image, the pasting image obtained from the target image can be pasted into the specified image. Of course, after obtaining the target image, it can also be applied in the saving scene and directly stored for later use.
[0161] It should be noted that, when there are multiple objects, each object corresponds to a pasted image.
[0162] In the disclosed embodiment, the background of the pasted image is set to be transparent, so that when the pasted image is pasted into a specified image, the pasted image can be directly superimposed on the specified image, so that the object can be quickly integrated into the specified image, thereby improving pasting efficiency.
[0163] It should be noted that the designated image may be any designated image of interest. For example, the designated image is a group photo, and the object is pasted into the group photo so that all persons are included in the group photo.
[0164] In the embodiment of the present disclosure, in the process of pasting the pasted image on the designated image, the pasted image may be rotated and / or scaled. For example, the pasted image may be rotated around the central pixel of the pasted image by using a rotation matrix; or, for another example, the pasted image may be enlarged or reduced by upsampling or downsampling.
[0165] The present disclosure also provides an image capture device. Figure 6 As shown, the image capturing device 1000 may include:
[0166] The acquisition module 1001 is configured to acquire the touch position information of the image to be extracted;
[0167] The detection module 1002 is configured to detect the object associated with the touch position information in the image to be extracted, and obtain the frame information of the object;
[0168] The first segmentation module 1003 is configured to use a first image segmentation model to segment the object in the image to be extracted to obtain a target image when the pixel ratio of the object determined according to the border information is greater than or equal to a first threshold and less than or equal to a second threshold.
[0169] In some embodiments, the device further comprises:
[0170] A second segmentation module is configured to use a second image segmentation model to perform target segmentation on the object in the image to be extracted to obtain the target image when the pixel ratio of the object is greater than or equal to a third threshold;
[0171] The third segmentation module is configured to obtain the target image based on the first pixel result obtained by segmentation of the first image segmentation model and the second pixel result obtained by segmentation of the second image segmentation model when the pixel proportion of the object is greater than the second threshold and less than the third threshold.
[0172] In some embodiments, the third segmentation module is further configured to average the pixel values in the first pixel result and the pixel values in the second pixel result to obtain an average pixel result; and construct the target image based on the average pixel result.
[0173] In some embodiments, the first segmentation module includes:
[0174] An extraction module, configured to extract features from the image to be extracted through a feature extraction structure of the first image segmentation model;
[0175] a fusion module, configured to fuse the extracted features through a feature fusion structure of the first image segmentation model to obtain a fused feature map;
[0176] The output module is configured to process the fused feature map through the side output structure of the first image segmentation model to obtain the target image.
[0177] In some embodiments, the output module is further configured to process the fused feature map through the first computing module of the side output structure to obtain output feature maps of different feature channels; to splice the output feature maps of different feature channels through the splicing module of the side output structure to obtain a spliced feature map; and to process the spliced feature map through the second computing module of the side output structure to obtain the target image.
[0178] In some embodiments, the apparatus further comprises:
[0179] A detection target module, configured to obtain a detection target based on the touch position information;
[0180] The detection acquisition module is configured to obtain the object based on the multiple detection targets when there are multiple detection targets.
[0181] In some embodiments, the detection acquisition module is further configured to treat at least two detection targets as one object when the pixel distance between at least two detection targets among the multiple detection targets is less than a distance threshold; and to treat each of the at least two detection targets as one object when the pixel distance between at least two detection targets among the multiple detection targets is greater than or equal to the distance threshold.
[0182] In some embodiments, the apparatus further comprises:
[0183] The pixel ratio determination module is configured to determine the area of the object according to the border pixel width and the border pixel height in the border information; and obtain the pixel ratio of the object based on the ratio of the area of the object to the pixel area of the image to be extracted.
[0184] In some embodiments, the border information includes: the minimum horizontal coordinate of the object in the pixel coordinate system, the minimum vertical coordinate of the object in the pixel coordinate system, the pixel width of the border of the object, and the pixel height of the border of the object.
[0185] In some embodiments, the apparatus further comprises:
[0186] The pasting module is configured to obtain a pasted image having the object from the target image, wherein the background of the pasted image is transparent; and paste the pasted image into a designated image.
[0187] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0188] Figure 7 800 is a block diagram of an electronic device according to an exemplary embodiment. For example, the electronic device 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0189] Reference Figure 7 , the electronic device 800 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output (I / O) interface 812 , a sensor component 814 , and a communication component 816 .
[0190] The processing component 802 generally controls the overall operation of the electronic device 800, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.
[0191] The memory 804 is configured to store various types of data to support operations on the device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0192] The power supply component 806 provides power to the various components of the electronic device 800. The power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 800.
[0193] The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and the rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0194] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the electronic device 800 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.
[0195] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0196] The sensor assembly 814 includes one or more sensors for providing various aspects of status assessment for the electronic device 800. For example, the sensor assembly 814 can detect the open / closed state of the device 800, the relative positioning of components, such as the display and keypad of the electronic device 800, and the sensor assembly 814 can also detect the position change of the electronic device 800 or a component of the electronic device 800, the presence or absence of contact between the user and the electronic device 800, the orientation or acceleration / deceleration of the electronic device 800, and the temperature change of the electronic device 800. The sensor assembly 814 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 814 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0197] The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 can access a wireless network based on a communication standard, such as WiFi, 3G or 5G, or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0198] In an exemplary embodiment, the electronic device 800 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.
[0199] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 804 including instructions, and the instructions can be executed by a processor 820 of an electronic device 800 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0200] A non-temporary computer-readable storage medium, when the instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to execute an image extraction method, the method comprising: obtaining touch position information of a touched image to be extracted; detecting an object associated with the touch position information in the image to be extracted to obtain border information of the object; and when the pixel ratio of the object determined according to the border information is greater than or equal to a first threshold and less than or equal to a second threshold, using a first image segmentation model to segment the object in the image to be extracted to obtain a target image.
[0201] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0202] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. An image extraction method, characterized in that: include: Acquire touch position information of the image to be extracted; Detecting an object associated with the touch position information in the image to be extracted to obtain frame information of the object; When the pixel ratio of the object determined according to the border information is greater than or equal to a first threshold and less than or equal to a second threshold, the object in the image to be extracted is segmented using a first image segmentation model to obtain a target image.
2. The method according to claim 1, characterized in that The method further comprises: When the pixel ratio of the object is greater than or equal to a third threshold, segmenting the object in the image to be extracted using a second image segmentation model to obtain the target image; When the pixel proportion of the object is greater than the second threshold and less than the third threshold, the target image is obtained based on the first pixel result obtained by segmentation of the first image segmentation model and the second pixel result obtained by segmentation of the second image segmentation model.
3. The method according to claim 2, characterized in that The step of obtaining the target image based on the first pixel result obtained by segmentation of the first image segmentation model and the second pixel result obtained by segmentation of the second image segmentation model comprises: Averaging the pixel values in the first pixel result and the pixel values in the second pixel result to obtain an average pixel result; The target image is constructed based on the average pixel results.
4. The method according to any one of claims 1 to 3, characterized in that: The step of using the first image segmentation model to segment the object in the image to be extracted to obtain a target image includes: Extracting features from the image to be extracted by using the feature extraction structure of the first image segmentation model; The extracted features are fused by the feature fusion structure of the first image segmentation model to obtain a fused feature map; The fused feature map is processed through the side output structure of the first image segmentation model to obtain the target image.
5. The method according to claim 4, characterized in that The step of processing the fused feature map through the side output structure of the first image segmentation model to obtain the target image includes: Processing the fused feature map through the first computing module of the side output structure to obtain output feature maps of different feature channels; The output feature maps of different feature channels are spliced by the splicing module of the side output structure to obtain a spliced feature map; The splicing feature map is processed by the second computing module of the side output structure to obtain the target image.
6. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Acquire a detection target based on the touch position information; In the case where there are multiple detection targets, the object is obtained based on the multiple detection targets.
7. The method according to claim 6, characterized in that The obtaining the object based on the plurality of detection targets comprises: In a case where the pixel distance between at least two of the plurality of detection targets is less than a distance threshold, treating the at least two detection targets as one object; In the case that the pixel distance between at least two of the multiple detection targets is greater than or equal to the distance threshold, each of the at least two detection targets is regarded as an object.
8. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Determine the area of the object according to the border pixel width and the border pixel height in the border information; Based on the ratio of the area of the object to the pixel area of the image to be extracted, the pixel ratio of the object is obtained.
9. The method according to any one of claims 1 to 3, characterized in that: The frame information includes: the minimum horizontal coordinate of the object in the pixel coordinate system, the minimum vertical coordinate of the object in the pixel coordinate system, the pixel width of the frame of the object, and the pixel height of the frame of the object.
10. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Acquire a pasted image having the object from the target image, wherein the background of the pasted image is transparent; Paste the paste image into the specified image.
11. An image extraction device, characterized in that: The device comprises: An acquisition module is configured to acquire touch position information of the image to be extracted; A detection module, configured to detect an object associated with the touch position information in the image to be extracted, and obtain frame information of the object; The first segmentation module is configured to use the first image segmentation model to segment the object in the image to be extracted to obtain a target image when the pixel ratio of the object determined according to the border information is greater than or equal to a first threshold and less than or equal to a second threshold.
12. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to execute the image extraction method according to any one of claims 1 to 10. 13 . A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the image extraction method according to any one of claims 1 to 10.
Citation Information
Patent Citations
A picture enhancement method and device for a small target
CN109948605A
Tool and method for segmenting target size
CN111833361A
Cited By
Image generation method and device based on large model, electronic equipment and storage medium
CN119444934A
