Image expansion processing method, device, electronic device and storage medium
By performing expansion processing based on the distance value between pixels in the image processing, the limitations of structural elements in the prior art are solved, and a low threshold and efficient image expansion effect is achieved, and image features are retained.
Patent Information
- Application Number
- CN202210696813.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-20
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2042-06-20
Smart Images

Figure CN115115557B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to an image expansion processing method, an image expansion processing device, an electronic device and a computer-readable storage medium. Background Art
[0002] Image dilation refers to adding pixel values to the edge of the image so that the overall pixel value expands, thereby achieving the image dilation effect.
[0003] The current dilation methods are all based on the dilation processing of the image based on the structure element, that is, a structure element with a certain size and a specific shape is predefined, and then the dilation processing is performed by calculating the maximum value of the sliding structure element.
[0004] However, the above method must pre-select the shape and size of the structural element, which requires developers to use experience to pre-calculate a more reasonable combination of structural element shapes and sizes as an alternative, so the development threshold is high. Secondly, since it is impossible to know which size and shape of structural elements are more effective, this requires technicians to constantly select structural elements of different shapes and sizes for combination tests to achieve the best effect, so the testing cost is high. Furthermore, the shape of the structural element is generally a cross, diamond and rectangle. The shape of the structural element determines that it cannot fit the edge of the target pixel, so after the expansion operation, it will cause the loss of the characteristics of the target pixel and change the original morphological characteristics of the target pixel. Summary of the invention
[0005] In view of the above problems, embodiments of the present invention are proposed to provide an image dilation processing method that overcomes the above problems or at least partially solves the above problems.
[0006] The embodiment of the present invention also provides an image expansion processing device, an electronic device and a storage medium to ensure the implementation of the above method.
[0007] In order to solve the above problem, an embodiment of the present invention discloses a method for image expansion processing, the method comprising:
[0008] Acquire an image to be processed; the image to be processed includes pixels to be identified and background pixels;
[0009] Assigning a target pixel value to the pixel to be identified, and assigning a non-target pixel value to the background pixel;
[0010] Calculate the distance between each target pixel value and each non-target pixel value respectively;
[0011] According to the distance value, the image formed by the pixels to be identified is expanded.
[0012] Optionally, before respectively calculating the distance values between each target pixel value and each non-target pixel value, the method further includes:
[0013] Inverting the pixel value of each pixel so that the pixel value of the pixel to be identified is updated to a non-target pixel value, and the pixel value of the background pixel is updated to a target pixel value;
[0014] The pixel value of each pixel corresponds to a plurality of distance values; and the image formed by the pixels to be identified is expanded according to the distance values, including:
[0015] For the target pixel value of each background pixel, determining a minimum distance value from the multiple distance values;
[0016] Updating the target pixel value of each background pixel to the corresponding minimum distance value, and updating the non-target pixel value of each pixel to be identified to the preset distance value;
[0017] According to the minimum distance value and the preset distance value, dilation processing is performed on the image composed of the pixels to be identified.
[0018] Optionally, the dilation processing of the image composed of the pixels to be identified according to the minimum distance value and the preset distance value includes:
[0019] Determining whether the minimum distance value is greater than a distance threshold, and determining whether the preset distance value is greater than a distance threshold;
[0020] If the minimum distance value is not greater than the distance threshold, updating the minimum distance value of the background pixel to the target pixel value; and,
[0021] If the preset distance value is not greater than the distance threshold, the preset distance value of the pixel to be identified is updated to the target pixel value.
[0022] Optionally, the method further comprises:
[0023] If the minimum distance value is greater than the distance threshold, updating the minimum distance value of the background pixel to a non-target pixel value; and,
[0024] If the preset distance value is greater than the distance threshold, the preset distance value of the pixel to be identified is updated to a non-target pixel value.
[0025] Optionally, the pixel value of each pixel corresponds to a plurality of distance values; and the dilation processing of the image formed by the pixels to be identified according to the distance values comprises:
[0026] For the non-target pixel value of each background pixel, determining a minimum distance value from the multiple distance values;
[0027] According to the minimum distance value, the image formed by the pixels to be identified is expanded.
[0028] Optionally, the dilation processing of the image formed by the pixels to be identified according to the minimum distance value includes:
[0029] Determine whether the minimum distance value is greater than a distance threshold;
[0030] If the minimum distance value is not greater than the distance threshold, the non-target pixel value of the background pixel is updated to the target pixel value.
[0031] Optionally, respectively calculating the distance values between each target pixel value and each non-target pixel value includes:
[0032] A calculation formula for pixel distance is used to calculate the distance value between each target pixel value and each non-target pixel value respectively; the calculation formula for pixel distance includes at least one of the calculation formulas for Euclidean distance, Manhattan distance, Chebyshev distance, Minkowski distance and standardized Euclidean distance.
[0033] The embodiment of the present invention further discloses an image expansion processing device, the device comprising:
[0034] The module for acquiring an image to be processed is used to acquire an image to be processed; the image to be processed includes pixels to be identified and background pixels;
[0035] A pixel value assignment module, used for assigning a target pixel value to the pixel to be identified, and assigning a non-target pixel value to the background pixel;
[0036] A distance value calculation module is used to calculate the distance value between each target pixel value and each non-target pixel value respectively;
[0037] The expansion processing module is used to perform expansion processing on the image composed of the pixels to be identified according to the distance value.
[0038] Optionally, before respectively calculating the distance values between each target pixel value and each non-target pixel value, the device further includes:
[0039] A pixel value inversion module, used for inverting the pixel value of each pixel, so that the pixel value of the pixel to be identified is updated to a non-target pixel value, and the pixel value of the background pixel is updated to a target pixel value;
[0040] The pixel value of each pixel corresponds to a plurality of distance values; the expansion processing module comprises:
[0041] A first minimum distance value determination submodule, configured to determine a minimum distance value from the multiple distance values for a target pixel value of each background pixel;
[0042] An updating submodule, used to update the target pixel value of each background pixel to a corresponding minimum distance value, and to update the non-target pixel value of each to-be-identified pixel to a preset distance value;
[0043] The first expansion processing submodule is used to perform expansion processing on the image composed of the pixels to be identified according to the minimum distance value and the preset distance value.
[0044] Optionally, the first expansion processing submodule includes:
[0045] A first judging unit, configured to judge whether the minimum distance value is greater than a distance threshold, and to judge whether the preset distance value is greater than a distance threshold;
[0046] a first updating unit, configured to update the minimum distance value of the background pixel to a target pixel value if the minimum distance value is not greater than a distance threshold; and
[0047] The second updating unit is configured to update the preset distance value of the pixel to be identified to a target pixel value if the preset distance value is not greater than a distance threshold.
[0048] Optionally, the device further comprises:
[0049] a first updating module, configured to update the minimum distance value of the background pixel to a non-target pixel value if the minimum distance value is greater than a distance threshold; and
[0050] The second updating module is used to update the preset distance value of the pixel to be identified to a non-target pixel value if the preset distance value is greater than the distance threshold.
[0051] Optionally, the pixel value of each pixel corresponds to a plurality of distance values; and the dilation processing module comprises:
[0052] A second minimum distance value determination submodule, configured to determine a minimum distance value from the multiple distance values for the non-target pixel value of each background pixel;
[0053] The second dilation processing submodule is used to perform dilation processing on the image composed of the pixels to be identified according to the minimum distance value.
[0054] Optionally, the second expansion processing submodule includes:
[0055] A second judging unit, used to judge whether the minimum distance value is greater than a distance threshold;
[0056] The third updating unit is configured to update the non-target pixel value of the background pixel to the target pixel value if the minimum distance value is not greater than the distance threshold.
[0057] Optionally, the distance value calculation module includes:
[0058] The distance value calculation submodule is used to respectively calculate the distance value between each target pixel value and each non-target pixel value by using a calculation formula for pixel distance; the calculation formula for pixel distance includes at least one of the calculation formulas for Euclidean distance, Manhattan distance, Chebyshev distance, Minkowski distance and standardized Euclidean distance.
[0059] The embodiment of the present invention further discloses an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0060] The memory is used to store computer programs;
[0061] The processor is used to implement the method described in the embodiment of the present invention when executing the program stored in the memory.
[0062] The embodiment of the present invention further discloses one or more computer-readable media on which instructions are stored. When executed by one or more processors, the processors are enabled to execute the method described in the embodiment of the present invention.
[0063] Compared with the prior art, the embodiments of the present invention have the following advantages:
[0064] In an embodiment of the present invention, an image to be processed is obtained, the image to be processed includes pixels to be identified and background pixels, then target pixel values are assigned to the pixels to be identified, and non-target pixel values are assigned to the background pixels, and then the distance values between each target pixel value and each non-target pixel value are calculated respectively, and finally, according to the distance values, the image composed of the pixels to be identified is expanded. The embodiment of the present invention performs expansion processing based on the distance between pixels, and there is no need to calculate or define the size and shape of the structural element in advance, so the development threshold is low, and there is no need to perform multiple multi-parameter combination tests of structural elements of different sizes and shapes, so as to save development resources, reduce testing costs, and can fit the edge of the pixel to be identified, so that the original features of the pixel to be identified can be retained to a great extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0066] Figure 1 This is the effect diagram of the expansion process for "1" in the prior art;
[0067] Figure 2 is a flowchart of the steps of an image expansion processing method provided by an embodiment of the present invention;
[0068] Figure 3 is a pixel value assignment diagram in an embodiment of the present invention;
[0069] Figure 4 is a pixel value negation diagram in an embodiment of the present invention;
[0070] Figure 5 is a pixel distance map in an embodiment of the present invention;
[0071] Figure 6 This is a diagram showing the effect of expansion treatment in an embodiment of the present invention;
[0072] Figure 7 is a diagram showing the effect of dilation processing performed on a pixel “1” to be identified in an embodiment of the present invention;
[0073] Figure 8 It is a structural diagram of a structural element in the prior art;
[0074] Fig. 9 It is a starting point diagram of the expansion process in the prior art;
[0075] Fig.10 This is the effect diagram of the prior art of performing a dilation process on a 3*3 "rectangle" of pixels to be identified;
[0076] Fig.11 This is the effect diagram of dilating the 3*3 "rectangle" of the pixel to be identified twice in the prior art;
[0077] Fig.12 is a pixel value negation diagram in an embodiment of the present invention;
[0078] Fig.13 is a pixel distance map in an embodiment of the present invention;
[0079] Fig.14 This is a diagram showing the effect of performing a dilation process once on a 3*3 “rectangle” of pixels to be identified in an embodiment of the present invention;
[0080] Fig.15It is a structural block diagram of an image expansion processing device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0081] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0082] The current dilation methods are all based on the dilation of the image based on the structural element, that is, a structural element with a certain size and shape is predefined, and then the dilation is performed by calculating the maximum value of the sliding structural element. Figure 1 , shows the effect of dilation processing on "1" in the prior art, wherein the dark block 101 is the pixel to be identified (target pixel), the white block 102 is the background pixel (non-target pixel), and the light block 103 is the pixel expanded after dilation processing. The dark block 101 constitutes "1", and the dilation processing of "1" using a 3*3 cross-shaped structural element can be obtained as follows Figure 1 The effect shown.
[0083] It can be seen that the above method must pre-select the shape and size of the structural element, which requires developers to use experience to pre-calculate a more reasonable combination of structural element shapes and sizes as an alternative, so the development threshold is high. Secondly, since it is impossible to know which size and shape of structural elements are better, this requires technicians to constantly select structural elements of different shapes and sizes for combination tests to achieve the best effect, so the testing cost is high. Furthermore, the shape of the structural element is generally a cross, diamond and rectangle. The shape of the structural element determines that it cannot fit the edge of the target pixel, so after the expansion operation, it will cause the loss of the characteristics of the target pixel and change the original morphological characteristics of the target pixel.
[0084] In view of the problems of high development threshold, high testing cost and easy loss of target pixel features in the above-mentioned dilation method based on structural elements, an embodiment of the present invention provides an image dilation processing method. The embodiment of the present invention performs dilation processing based on the distance between pixels, and there is no need to pre-calculate or define the size and shape of the structural element, so that the development threshold is low, and there is no need to perform multiple multi-parameter combination tests of structural elements of different sizes and shapes, thereby saving development resources and reducing testing costs. It can also fit the edge of the pixel to be identified, so that the original features of the pixel to be identified can be retained to the greatest extent.
[0085] Reference Figure 2, shows a flowchart of a method for image expansion processing provided by an embodiment of the present invention, the method may specifically include the following steps:
[0086] Step 201, obtaining an image to be processed; the image to be processed includes pixels to be identified and background pixels.
[0087] In an embodiment of the present invention, an image to be processed may be obtained, and the image to be identified may be composed of multiple pixels, and the pixels may include pixels to be identified and background pixels. The pixels to be identified may refer to all pixels constituting the objects to be identified in the foreground of the image to be processed. For example, if all apples need to be found in an image with apples, then all pixels constituting the apple image area in the image may be referred to as pixels to be identified. Background pixels may refer to all pixels constituting the background in the image to be processed. For example, if all apples need to be found in an image with apples, then all pixels constituting the non-apple image area in the image may be referred to as background pixels.
[0088] Step 202: assigning a target pixel value to the pixel to be identified, and assigning a non-target pixel value to the background pixel.
[0089] In the embodiment of the present invention, the target pixel value can be assigned to the pixel to be identified, and the non-target pixel value can be assigned to the background pixel, so that the pixel to be identified and the background pixel can be qualitatively separated. Specifically, the image to be processed can be converted into a grayscale image and binarized to obtain an image with pixel values of "0" and "255", wherein "0" represents black and "255" represents white. The pixel to be identified in the image at this time is assigned a target pixel value, and the background pixel is assigned a non-target pixel value, wherein the target pixel value can be "0" or "255", and the non-target pixel value can be "0" or "255". In addition, the target pixel value and the non-target pixel value can also be other numerical combinations, such as the target pixel value can be "1", and the non-target pixel value can be "0", as long as the target pixel value and the non-target pixel value are different numerical values, and the target pixel value and the non-target pixel value can be distinguished, the embodiment of the present invention does not limit this.
[0090] In one example, referring to Figure 3 , shows a pixel assignment diagram in an embodiment of the present invention, the image to be processed is an image containing 9*10 pixels, wherein the middle area of the image to be processed is the pixel to be identified, the pixel to be identified is a 5*6 rectangle, the target pixel value "1" can be assigned to the pixel to be identified, and the non-target pixel value "0" can be assigned to the background pixel, so that the following can be obtained: Figure 3 The pixel assignment diagram shown.
[0091] Step 203, respectively calculating the distance value between each target pixel value and each non-target pixel value.
[0092] In an embodiment of the present invention, the distance values of each target pixel value and each non-target pixel value can be calculated respectively. For example, assuming that the non-target pixel values are A1, A2, A3, and the target pixel values are B1, B2, B3, and the distance values of each target pixel value and each non-target pixel value are calculated respectively, the distance values of (A1, B1), (A1, B2), (A1, B3), (A2, B1), (A2, B2), (A2, B3), (A3, B1), (A3, B2), (A3, B3) can be obtained. The example is only used to enable those skilled in the art to better understand the embodiment of the present invention, and the present invention does not limit this.
[0093] In an optional embodiment of the present invention, step 203 may include the following sub-steps:
[0094] Sub-step S31, using a calculation formula for pixel distance to respectively calculate the distance value between each target pixel value and each non-target pixel value; the calculation formula for pixel distance includes at least one of the calculation formulas for Euclidean distance, Manhattan distance, Chebyshev distance, Minkowski distance, and standardized Euclidean distance.
[0095] The distance value can be calculated using a calculation formula for pixel distance, and the calculation formula for pixel distance can include at least one of a calculation formula for Euclidean distance, a calculation formula for Manhattan distance, a calculation formula for Chebyshev distance, a calculation formula for Minkowski distance, and a calculation formula for standardized Euclidean distance.
[0096] Specifically, the Euclidean distance is a commonly used distance definition formula. It is the true distance between two points in m-dimensional space. The Euclidean distance in two-dimensional space is the straight line distance between two points. Then the Euclidean distance between a(x1,y1) and b(x2,y2) in the two-dimensional plane is:
[0097]
[0098] Specifically, Manhattan distance is a geometric term used in geometric metric space to indicate the sum of the absolute distances between two points in a standard coordinate system. The Manhattan distance between a(x1,y1) and b(x2,y2) in a two-dimensional plane is:
[0099] d=|x1-x2|+|y1-y2| (Formula 2)
[0100] Specifically, the Chebyshev distance or L∞ metric is a metric in vector space. The distance between two points is defined as the maximum absolute value of the difference between their coordinate values. The Chebyshev distance between a(x1,y1) and b(x2,y2) in a two-dimensional plane is:
[0101] d=max(|x1-x2|,|y1-y2|) (Formula 3)
[0102] Specifically, Minkowski distance is a common method to measure the distance between numerical points. Assume that the coordinates of numerical points P and Q are as follows:
[0103] P=(x1,x2,...,x n )andQ=(y1,y2,...,y n )∈R n (Formula 4)
[0104] Then the Minkowski distance is:
[0105]
[0106] Specifically, the standardized Euclidean distance is to normalize the set first and map it to the interval of normal distribution N(0,1), then the standardized Euclidean distance is:
[0107]
[0108] It should be noted that for general two-dimensional images, Euclidean distance, Manhattan distance, and Chebyshev distance can be used. If you want to calculate the straight-line distance between pixels, you can use Euclidean distance. If you want to calculate the accumulation of absolute distances of horizontal and vertical coordinates, you can use Manhattan distance. The choice of calculation formula can be determined by the user.
[0109] In addition, the above calculation formula can be improved according to specific usage to obtain a custom formula. For example, if you want to amplify the influence coefficient of the horizontal axis, you can improve the Manhattan distance to become:
[0110] d=2*|x1-x2|+|y1-y2| (Formula 7)
[0111] Step 204: dilate the image composed of the pixels to be identified according to the distance value.
[0112] In the embodiment of the present invention, after the distance values between each target pixel value and each non-target pixel value are calculated, the distance values may be used to perform dilation processing on the image composed of the pixels to be identified.
[0113] In an optional embodiment of the present invention, before respectively calculating the distance values between each target pixel value and each non-target pixel value, the method may further include:
[0114] The pixel value of each pixel is inverted so that the pixel value of the pixel to be identified is updated to a non-target pixel value, and the pixel value of the background pixel is updated to a target pixel value.
[0115] In the embodiment of the present invention, before respectively calculating the distance values between each target pixel value and each non-target pixel value, the pixel values of all pixels may be inverted so that the pixel value of the pixel to be identified is updated to the non-target pixel value and the pixel value of the background pixel is updated to the target pixel value. Figure 4 , shows a pixel value inversion diagram in an embodiment of the present invention, Figure 4 It is through Figure 3 The image is obtained by inverting the pixel values of all pixels in the image, that is, the pixels to be identified whose original value is 1 are reassigned to 0, and the background pixels whose original value is 0 are reassigned to 1.
[0116] In an optional embodiment of the present invention, the pixel value of each pixel corresponds to a plurality of distance values; step 204 may include the following sub-steps:
[0117] Sub-step S11 , determining a minimum distance value from the multiple distance values for the target pixel value of each background pixel.
[0118] In one example, if Figure 4 As shown, after calculating the distance values between each target pixel value (such as A1, A2, A3) and each non-target pixel value (such as B1, B2, B3), the pixel value of each pixel can correspond to multiple distance values. For example, the target pixel value A1 can correspond to The examples are only used to help those skilled in the art better understand the embodiments of the present invention, and the present invention does not limit this.
[0119] Depend on Figure 3 and Figure 4It can be seen that after the pixel values of each pixel are inverted in the embodiment of the present invention, the pixel value of the pixel to be identified changes from the target pixel value "1" to the non-target pixel value "0", and the pixel value of the background pixel changes from the non-target pixel value "0" to the target pixel value "1". Therefore, for each background pixel, that is, for each target pixel value "1" after inversion, the minimum distance between each target pixel value "1" after inversion and the non-target pixel value "0" closest to itself can be determined respectively. Specifically, the minimum distance value can be found through the multiple distance values corresponding to itself. For example, for the target pixel value A1, from Select the minimum distance value, the minimum distance value can be The examples are only used to help those skilled in the art to better understand the embodiments of the present invention, and the present invention is not limited thereto.
[0120] Sub-step S12, updating the target pixel value of each background pixel to the corresponding minimum distance value, and updating the non-target pixel value of each pixel to be identified to a preset distance value;
[0121] Sub-step S13, dilating the image composed of the pixels to be identified according to the minimum distance value and the preset distance value.
[0122] In the embodiment of the present invention, after finding the minimum distance value corresponding to each background pixel, the target pixel value of each background pixel can be updated to the corresponding minimum distance value, and the non-target pixel value of each pixel to be identified can be updated to the preset distance value. The preset distance value can be the minimum distance between each non-target pixel value after negation and the non-target pixel value closest to itself. Since the non-target pixel value closest to the non-target pixel value is itself, the preset distance value can be 0.
[0123] In one example, if Figure 4 As shown, the distances from A1, A2, A3 to B1 are all the minimum distance values, among which the distance from A1 to B1 is The distance between A2 and B1 is The distance between A3 and B1 is 2, so the target pixel value of A1, "1", can be updated to the distance value. And the target pixel value "1" of A2 can be updated to the distance value And the target pixel value "1" of A3 can be updated to the distance value "2", so that the following can be obtained: Figure 5 The pixel distance map shown in Figure 5 The minimum distance value of each target pixel value and the preset distance value of each non-target pixel value in the image to be identified are used to perform dilation processing on the image composed of the pixels to be identified. The examples are only used to enable those skilled in the art to better understand the embodiments of the present invention, and the present invention does not limit this.
[0124] In an optional embodiment of the present invention, sub-step S13 may include the following sub-steps:
[0125] Sub-step S131, determining whether the minimum distance value is greater than a distance threshold, and determining whether the preset distance value is greater than a distance threshold;
[0126] Sub-step S132, if the minimum distance value is not greater than the distance threshold, updating the minimum distance value of the background pixel to the target pixel value; and,
[0127] Sub-step S133: if the preset distance value is not greater than the distance threshold, the preset distance value of the pixel to be identified is updated to the target pixel value.
[0128] In the embodiment of the present invention, each minimum distance value can be compared with the distance threshold TH, and each preset distance value can be compared with the distance threshold TH. If the minimum distance value is not greater than the distance threshold TH, that is, the minimum distance value is less than or equal to the distance threshold TH, then the minimum distance value of the background pixel can be updated to the target pixel value to transform it into the type of the pixel to be identified, and if the preset distance value is not greater than the distance threshold TH, that is, the preset distance value is less than or equal to the distance threshold TH, then the preset distance value of the pixel to be identified can be updated to the target pixel value to maintain it as the type of the pixel to be identified.
[0129] It should be noted that the threshold TH can be modified according to actual needs. For example, if you want to uniformly expand the pixels to be identified by X distance units, you can set the distance threshold TH to
[0130] In one example, if the distance threshold TH is set to for Figure 5 All distance values in are less than or equal to The pixel whose distance value is updated to the target pixel value "1" is transformed / maintained as the type of the pixel to be identified, so that the following can be obtained: Figure 6 The effect diagram shown.
[0131] In addition to updating the distance values in the pixel distance map, you can also update the pixel values in the image before negation. Figure 5 The pixel distance at each position in the image, if the distance of the pixel at that position is not greater than the distance threshold TH, then the image before negation ( Figure 3 ) is updated to the target pixel value so that it is transformed / maintained as the type of pixel to be identified.
[0132] In an optional embodiment of the present invention, the method may further include:
[0133] If the minimum distance value is greater than the distance threshold, updating the minimum distance value of the background pixel to a non-target pixel value; and,
[0134] If the preset distance value is greater than the distance threshold, the preset distance value of the pixel to be identified is updated to a non-target pixel value.
[0135] In an embodiment of the present invention, if the minimum distance value is greater than the distance threshold TH, the minimum distance value of the background pixel can be updated to a non-target pixel value to maintain it as the type of the background pixel, and if the preset distance value is greater than the distance threshold TH, the preset distance value of the pixel to be identified can be updated to a non-target pixel value to transform it into the type of the background pixel.
[0136] In one example, if the distance threshold TH is set to for Figure 5 All distance values greater than The pixel whose distance value is updated to the non-target pixel value "0" is transformed / maintained as the type of background pixel, so that the following can be obtained: Figure 6 The effect diagram shown.
[0137] In addition to updating the distance values in the pixel distance map, you can also update the pixel values in the image before negation. Figure 5 The pixel distance at each position in the image, if the distance of the pixel at that position is greater than the distance threshold TH, then the image before inversion ( Figure 3 ) is updated to a non-target pixel value so that it is transformed / maintained as the type of background pixel.
[0138] In an optional embodiment of the present invention, the pixel value of each pixel corresponds to a plurality of distance values; step 204 may include the following sub-steps:
[0139] Sub-step S21, determining a minimum distance value from the multiple distance values for the non-target pixel value of each background pixel;
[0140] Sub-step S22: dilating the image composed of the pixels to be identified according to the minimum distance value.
[0141] The above-mentioned sub-steps S11 to S13 are steps for performing an inversion operation on the pixel values of the pixels, that is, the pixel values of the pixels to be identified after the inversion operation are non-target pixel values, and the pixel values of the background pixels after the inversion operation are target pixel values, while the present sub-steps S21 to S22 are steps for performing no inversion operation on the pixel values of the pixels, that is, the pixel values of the pixels to be identified are target pixel values, and the pixel values of the background pixels are non-target pixel values.
[0142] Regardless of whether the pixel value of the pixel is inverted, the pixel value of each pixel can correspond to multiple distance values. Therefore, for the non-target pixel value "0" of each background pixel, the minimum distance between each non-target pixel value "0" and the target pixel value "1" closest to itself can be determined. Specifically, the minimum distance value can be found among the corresponding multiple distance values, so that the image composed of the pixels to be identified can be expanded according to the minimum distance value.
[0143] In an optional embodiment of the present invention, sub-step S22 may include the following sub-steps:
[0144] Sub-step S221, for determining whether the minimum distance value is greater than a distance threshold;
[0145] Sub-step S222: if the minimum distance value is not greater than the distance threshold, updating the non-target pixel value of the background pixel to the target pixel value.
[0146] In the embodiment of the present invention, each minimum distance value can be compared with the distance threshold TH. If the minimum distance value is not greater than the distance threshold TH, that is, the minimum distance value is less than or equal to the distance threshold TH, then the non-target pixel value "0" of the background pixel can be updated to the target pixel value "1" to transform it into the type of the pixel to be identified; if the minimum distance value is greater than the distance threshold TH, then the non-target pixel value "0" of the background pixel can be not updated to maintain it as the type of the background pixel.
[0147] refer to Figure 7 , shows the effect of dilation processing for the pixel to be identified "1" in the embodiment of the present invention, wherein the dark block 701 is the pixel to be identified, the white block 702 is the background pixel, and the light block 703 is the pixel expanded after dilation processing, which is different from the prior art. Figure 1 In comparison, the embodiment of the present invention Figure 7 The original features of the pixel "1" to be identified can be well preserved.
[0148] In an embodiment of the present invention, an image to be processed is obtained, the image to be processed includes pixels to be identified and background pixels, then target pixel values are assigned to the pixels to be identified, and non-target pixel values are assigned to the background pixels, and then the distance values between each target pixel value and each non-target pixel value are calculated respectively, and finally, according to the distance values, the image composed of the pixels to be identified is expanded. The embodiment of the present invention performs expansion processing based on the distance between pixels, and there is no need to calculate or define the size and shape of the structural element in advance, so the development threshold is low, and there is no need to perform multiple multi-parameter combination tests of structural elements of different sizes and shapes, so as to save development resources, reduce testing costs, and can fit the edge of the pixel to be identified, so that the original features of the pixel to be identified can be retained to a great extent.
[0149] In order to enable those skilled in the art to better understand the expansion method of the prior art and the expansion method of the embodiment of the present invention, the following two examples are used for comparison and explanation:
[0150] Example 1: Expansion method of prior art
[0151] Assume that a Figure 8 The 3*3 rectangular structural element shown is Fig. 9 As the starting point, first Figure 8 The anchor point A in the structural element of Fig. 9 Align the anchor point B in the image and then calculate Fig. 9 The maximum value of the area centered on anchor point B and covered by the structural element, that is, the maximum value of the 3*3 rectangular area centered on anchor point B, can determine that point C is the maximum value, then this maximum value can be assigned to the position of anchor point B, and then continue to slide the structural element to calculate the maximum value of the next position.
[0152] After the expansion process, we can get Fig.10 The effect diagram shown. It can be seen that Fig. 9 The pixel value of anchor point B in Fig.10 becomes "1", and Fig. 9 The pixels to be identified in the image expand outwards in a circle, from virtual frame 90 to virtual frame 100.
[0153] After two dilation processes, we can get Fig.11 The effect diagram shown. It can be seen that Fig. 9 The pixels to be identified in the image are expanded outward by two circles, and the virtual frame 90 is changed into the virtual frame 110.
[0154] It can be seen that the expansion method of the prior art requires Fig. 9 Operation twice to get the expected Fig.11 effect.
[0155] Example 2: Expansion method according to an embodiment of the present invention
[0156] First, the target pixel value "1" is assigned to the pixel to be identified, and the non-target pixel value "0" is assigned to the background pixel. Then, the pixel values of all pixels can be inverted so that the pixel value of the pixel to be identified changes from the target pixel value "1" to the non-target pixel value "0", and the pixel value of the background pixel changes from the non-target pixel value "0" to the target pixel value "1", so that Fig.12 Then, the distance values between each target pixel value and each non-target pixel value can be calculated respectively, and then the target pixel value of each background pixel can be updated to the corresponding minimum distance value, and the non-target pixel value of each pixel to be identified can be updated to the preset distance value, so that Fig.13 The pixel distance map shown. Finally, the distance threshold can be The distance value of the pixel is updated to the target pixel value "1", and the pixel greater than the distance threshold can be The distance value of the pixel is updated to the non-target pixel value "0", so that Fig.14 The effect diagram shown.
[0157] It can be seen that the expansion method of the embodiment of the present invention only requires Fig.12 You can get the expected result by operating it once Fig.14 The virtual frame 120 is changed into the virtual frame 140.
[0158] The image expansion processing method provided by the embodiment of the present invention can be applied to the following scenarios:
[0159] Scenario 1: Involves a custom opening operation.
[0160] "Opening operation" or "opening calculation" is a common term in the industry. Generally, it refers to a sequential erosion and expansion, which is called an opening operation. The steps are as follows:
[0161] Step 1, first perform corrosion operation on the image;
[0162] Step 2: Perform the dilation operation of the embodiment of the present invention on the image.
[0163] Scenario 2: Involves a custom closing operation.
[0164] "Closing operation" or "closing operation" is a common term in the industry. Generally, it refers to a dilation and an erosion in sequence, which is called a closing operation. The steps are as follows:
[0165] Step 1, firstly perform a dilation operation on the image according to an embodiment of the present invention;
[0166] Step 2: perform corrosion operation on the image.
[0167] Scenario 3: A solution for extracting text pixels from an image
[0168] Step 1: Use a pre-trained object detection model to extract the image to be processed at the location of the text pixels in the initial image;
[0169] Step 2: Convert the extracted image to be processed into a grayscale image, perform binarization, assign the target pixel value "1" to the pixel value of the text pixel, and assign the non-target pixel value "0" to the pixel value of the background pixel;
[0170] Step 3: Perform an erosion operation on the text pixels to remove noise pixels and rough edge pixels;
[0171] Step 4: Perform the dilation operation of the embodiment of the present invention on the text pixels to enhance the characteristics of the text pixels, and finally obtain the text pixels in the image.
[0172] refer to Fig.15 , shows a structural block diagram of an image expansion processing device provided by an embodiment of the present invention, which may specifically include the following modules:
[0173] The to-be-processed image acquisition module 1501 is used to acquire the to-be-processed image; the to-be-processed image includes pixels to be identified and background pixels;
[0174] A pixel value assignment module 1502 is used to assign a target pixel value to the pixel to be identified, and to assign a non-target pixel value to the background pixel;
[0175] The distance value calculation module 1503 is used to calculate the distance value between each target pixel value and each non-target pixel value respectively;
[0176] The dilation processing module 1504 is used to dilate the image composed of the pixels to be identified according to the distance value.
[0177] In an optional embodiment of the present invention, before respectively calculating the distance values between each target pixel value and each non-target pixel value, the apparatus may further include:
[0178] A pixel value inversion module, used for inverting the pixel value of each pixel, so that the pixel value of the pixel to be identified is updated to a non-target pixel value, and the pixel value of the background pixel is updated to a target pixel value;
[0179] The pixel value of each pixel corresponds to a plurality of distance values; the dilation processing module 1504 may include:
[0180] A first minimum distance value determination submodule, configured to determine a minimum distance value from the multiple distance values for a target pixel value of each background pixel;
[0181] An updating submodule, used to update the target pixel value of each background pixel to a corresponding minimum distance value, and to update the non-target pixel value of each to-be-identified pixel to a preset distance value;
[0182] The first expansion processing submodule is used to perform expansion processing on the image composed of the pixels to be identified according to the minimum distance value and the preset distance value.
[0183] In an optional embodiment of the present invention, the first expansion processing submodule may include:
[0184] A first judging unit, configured to judge whether the minimum distance value is greater than a distance threshold, and to judge whether the preset distance value is greater than a distance threshold;
[0185] a first updating unit, configured to update the minimum distance value of the background pixel to a target pixel value if the minimum distance value is not greater than a distance threshold; and
[0186] The second updating unit is configured to update the preset distance value of the pixel to be identified to a target pixel value if the preset distance value is not greater than a distance threshold.
[0187] In an optional embodiment of the present invention, the device may further include:
[0188] a first updating module, configured to update the minimum distance value of the background pixel to a non-target pixel value if the minimum distance value is greater than a distance threshold; and
[0189] The second updating module is used to update the preset distance value of the pixel to be identified to a non-target pixel value if the preset distance value is greater than the distance threshold.
[0190] In an optional embodiment of the present invention, the pixel value of each pixel corresponds to multiple distance values; the expansion processing module 1504 may include:
[0191] A second minimum distance value determination submodule, configured to determine a minimum distance value from the multiple distance values for the non-target pixel value of each background pixel;
[0192] The second dilation processing submodule is used to perform dilation processing on the image composed of the pixels to be identified according to the minimum distance value.
[0193] In an optional embodiment of the present invention, the second expansion processing submodule may include:
[0194] A second judging unit, used to judge whether the minimum distance value is greater than a distance threshold;
[0195] The third updating unit is configured to update the non-target pixel value of the background pixel to the target pixel value if the minimum distance value is not greater than the distance threshold.
[0196] In an optional embodiment of the present invention, the distance value calculation module may include:
[0197] The distance value calculation submodule is used to respectively calculate the distance value between each target pixel value and each non-target pixel value by using a calculation formula for pixel distance; the calculation formula for pixel distance includes at least one of the calculation formulas for Euclidean distance, Manhattan distance, Chebyshev distance, Minkowski distance and standardized Euclidean distance.
[0198] In an embodiment of the present invention, an image to be processed is obtained, the image to be processed includes pixels to be identified and background pixels, then target pixel values are assigned to the pixels to be identified, and non-target pixel values are assigned to the background pixels, and then the distance values between each target pixel value and each non-target pixel value are calculated respectively, and finally, according to the distance values, the image composed of the pixels to be identified is expanded. The embodiment of the present invention performs expansion processing based on the distance between pixels, and there is no need to calculate or define the size and shape of the structural element in advance, so the development threshold is low, and there is no need to perform multiple multi-parameter combination tests of structural elements of different sizes and shapes, so as to save development resources, reduce testing costs, and can fit the edge of the pixel to be identified, so that the original features of the pixel to be identified can be retained to a great extent.
[0199] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0200] An embodiment of the present invention further provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, each process of the above-mentioned image expansion processing method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0201] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned image expansion processing method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0202] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0203] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0204] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0205] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0206] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0207] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0208] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0209] The above is a detailed introduction to the image expansion processing method, device, electronic device and computer-readable storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method and core idea of the present invention. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A method for image expansion processing, characterized in that: The method comprises: Acquire an image to be processed; the image to be processed includes pixels to be identified and background pixels; Assigning a target pixel value to the pixel to be identified, and assigning a non-target pixel value to the background pixel; Inverting the pixel value of each pixel so that the pixel value of the pixel to be identified is updated to a non-target pixel value, and the pixel value of the background pixel is updated to a target pixel value; Calculate the distance between each target pixel value and each non-target pixel value respectively; the pixel value of each pixel corresponds to multiple distance values; According to the distance value, dilation processing is performed on the image composed of the pixels to be identified; The step of performing dilation processing on the image composed of the pixels to be identified according to the distance value includes: For the target pixel value of each background pixel, determining a minimum distance value from the multiple distance values; Updating the target pixel value of each background pixel to the corresponding minimum distance value, and updating the non-target pixel value of each pixel to be identified to the preset distance value; According to the minimum distance value and the preset distance value, dilation processing is performed on the image composed of the pixels to be identified.
2. The method according to claim 1, characterized in that The step of performing dilation processing on the image composed of the pixels to be identified according to the minimum distance value and the preset distance value includes: Determining whether the minimum distance value is greater than a distance threshold, and determining whether the preset distance value is greater than a distance threshold; If the minimum distance value is not greater than the distance threshold, updating the minimum distance value of the background pixel to the target pixel value; and, If the preset distance value is not greater than the distance threshold, the preset distance value of the pixel to be identified is updated to the target pixel value.
3. The method according to claim 2, characterized in that The method further comprises: If the minimum distance value is greater than the distance threshold, updating the minimum distance value of the background pixel to a non-target pixel value; and, If the preset distance value is greater than the distance threshold, the preset distance value of the pixel to be identified is updated to a non-target pixel value.
4. The method according to claim 1, characterized in that The pixel value of each pixel corresponds to a plurality of distance values; and the image formed by the pixels to be identified is expanded according to the distance values, including: For the non-target pixel value of each background pixel, determining a minimum distance value from the multiple distance values; According to the minimum distance value, the image formed by the pixels to be identified is expanded.
5. The method according to claim 4, characterized in that The step of performing dilation processing on the image composed of the pixels to be identified according to the minimum distance value comprises: Determine whether the minimum distance value is greater than a distance threshold; If the minimum distance value is not greater than the distance threshold, the non-target pixel value of the background pixel is updated to the target pixel value.
6. The method according to claim 1, characterized in that The respectively calculating the distance values between each target pixel value and each non-target pixel value comprises: A calculation formula for pixel distance is used to calculate the distance value between each target pixel value and each non-target pixel value respectively; the calculation formula for pixel distance includes at least one of the calculation formulas for Euclidean distance, Manhattan distance, Chebyshev distance, Minkowski distance and standardized Euclidean distance.
7. An image expansion processing device, characterized in that: The device comprises: The module for acquiring an image to be processed is used to acquire an image to be processed; the image to be processed includes pixels to be identified and background pixels; A pixel value assignment module, used for assigning a target pixel value to the pixel to be identified, and assigning a non-target pixel value to the background pixel; A pixel value inversion module, used for inverting the pixel value of each pixel, so that the pixel value of the pixel to be identified is updated to a non-target pixel value, and the pixel value of the background pixel is updated to a target pixel value; A distance value calculation module is used to calculate the distance value between each target pixel value and each non-target pixel value respectively; the pixel value of each pixel corresponds to multiple distance values; An expansion processing module is used to perform expansion processing on the image composed of the pixels to be identified according to the distance value; the expansion processing module includes: A first minimum distance value determination submodule, configured to determine a minimum distance value from the multiple distance values for a target pixel value of each background pixel; An updating submodule, used to update the target pixel value of each background pixel to a corresponding minimum distance value, and to update the non-target pixel value of each to-be-identified pixel to a preset distance value; The first expansion processing submodule is used to perform expansion processing on the image composed of the pixels to be identified according to the minimum distance value and the preset distance value.
8. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the image dilation processing method according to any one of claims 1 to 6 are implemented.
9. 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 steps of the image dilation processing method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Composite video streaming using stateless compression
AU2015203292A1
Image processing method and device, electronic equipment and computer readable storage medium
CN112862852A
Image processing method and device
CN113689364A
Image data processing method and device, computer equipment and storage medium
CN113870154A
Image corrosion method, image processing method and device
CN114359119A
