Image segmentation method, image segmentation device, storage medium and electronic equipment
By fitting and fusing row and queue threshold images by least squares method, the segmentation difficulty of high-frequency signal targets in the case of uneven background is solved, and the accuracy and completeness of image segmentation are achieved.
Patent Information
- Application Number
- CN202410920997.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-11-22
AI Technical Summary
The existing image segmentation method cannot accurately segment the foreground image due to background inhomogeneity when processing high-frequency signal targets, and it is difficult to accurately obtain the target position of the local threshold.
The least squares method is used to fit the pixel grayscale values of each row and each column of the image to obtain the grayscale distribution function of rows and columns. These functions are used to correct the actual grayscale values to generate the row and column threshold image, and the It blends to obtain a foreground image.
It improves the accuracy of image segmentation, minimizes interference in uneven background areas, ensures the integrity of the target, and solves the problem that the single-direction threshold cannot completely segment the target.
Smart Images

Figure CN119006509A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular, to an image segmentation method, an image segmentation device, a computer-readable storage medium, and an electronic device. Background Art
[0002] When segmenting high-frequency signal targets from an uneven image, if a global threshold is used to extract the target, due to the unevenness of the background, the grayscale value of part of the background may be greater than (or less than) the grayscale value of the target to be extracted, resulting in the inability to accurately extract the target. If a local threshold is used, the extracted targets are randomly distributed in the image, and the specific position cannot be accurately obtained, which makes it difficult to extract the target. Summary of the invention
[0003] The main purpose of the present application is to provide an image segmentation method, an image segmentation device, a computer-readable storage medium and an electronic device, so as to at least solve the problem that the existing image segmentation method cannot accurately segment the foreground image when targeting high-frequency signal targets.
[0004] In order to achieve the above-mentioned purpose, according to one aspect of the present application, an image segmentation method is provided, comprising: inputting an image to be processed, wherein the image to be processed comprises a foreground image and a background image, and the foreground image comprises a high-frequency signal image; using the least squares method to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, and using the least squares method to fit the grayscale values of each pixel in each column of the image to be processed to obtain a quadratic function to obtain a column grayscale distribution function of each column; using each of the row grayscale distribution functions to correct the actual grayscale values of each pixel in each row of the image to be processed to obtain a row threshold image of the image to be processed, and using each of the column grayscale distribution functions to correct the actual grayscale values of each pixel in each column of the image to be processed to obtain a column threshold image of the image to be processed; and fusing the row threshold image and the column threshold image to obtain the foreground image.
[0005] Optionally, the least squares method is used to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, including: obtaining the grayscale values of all pixel points in the current row of the image to be processed, and storing them in a first array in a first order; converting each data in the first array into corresponding two-dimensional coordinate data, one of the two-dimensional coordinate data consists of x and y, wherein x represents the order of the pixel points corresponding to the two-dimensional coordinate data, and y represents the actual grayscale value of the pixel point corresponding to the two-dimensional coordinate data; using the least squares method to fit each of the two-dimensional coordinate data to obtain the row grayscale distribution function.
[0006] Optionally, the least square method is used to fit each of the two-dimensional coordinate data to obtain the row grayscale distribution function, including: defining the row grayscale distribution function as y θ =θ0+θ1x1+θ2x2+……+θ n x n ;
[0007] Determine the loss function Wherein, j is the difference between the actual grayscale value of the pixel and the fitted grayscale value, h θ is the fitting grayscale value of the pixel point being fitted, m is the total number of rows of the image to be processed, x is the sequence number of the pixel, y is the actual gray value of the pixel, θ is the function coefficient of the row gray distribution function, θ n is the nth coefficient in the grayscale distribution function, n is the feature dimension; according to the loss function, the function coefficient θ=(X T X) -1 X T Y, and determine the row grayscale distribution function according to the function coefficient.
[0008] Optionally, the actual grayscale value of each pixel in each row of the image to be processed is corrected by using each of the row grayscale distribution functions to obtain a row threshold image of the image to be processed, including: obtaining a threshold coefficient for each row of the image to be processed; determining a fitting grayscale value for each pixel in the current row according to the row grayscale distribution function; Among them, x i is the position of the i-th pixel in the current row; the product of the fitting grayscale value and the threshold coefficient is determined as the grayscale threshold of the pixel; and the row threshold image is determined according to the actual grayscale value of the pixel and the corresponding grayscale threshold.
[0009] Optionally, determining the row threshold image according to the actual grayscale value of the pixel and the corresponding grayscale threshold includes: when the actual grayscale value of the foreground image is greater than the actual grayscale value of the background image, according to the first formula Determine the grayscale value of the pixel in the row threshold image, where g(x i ) is the gray value of the pixel in the row threshold image, x i is the i-th pixel of the current row, y i is the gray value of the i-th pixel in the image to be processed, T i is the grayscale threshold corresponding to the i-th pixel; when the actual grayscale value of the foreground image is less than the actual grayscale value of the background image, according to the second formula Determine the grayscale value of the pixel point in the row threshold image; and determine the row threshold image according to the grayscale value of each pixel point in the row threshold image.
[0010] Optionally, the row threshold image and the column threshold image are fused to obtain the foreground image, including: determining the sum of the grayscale value of the pixel point in the row threshold image and the grayscale value of the pixel point in the column threshold image as an intermediate grayscale value; when the intermediate grayscale value is greater than or equal to 255, determining the grayscale value of the pixel point in the foreground image as 255, and when the intermediate grayscale value is less than 255, determining the grayscale value of the pixel point in the foreground image as 0; and determining the foreground image according to the grayscale value of each pixel point in the foreground image.
[0011] Optionally, after inputting the image to be processed and before using the least squares method to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, the method also includes: performing median filtering on the image to be processed to eliminate noise in the image to be processed, wherein the size of the filter kernel is 5×5 pixels.
[0012] According to another aspect of the present application, an image segmentation device is provided, comprising: an input unit, for inputting an image to be processed, wherein the image to be processed comprises a foreground image and a background image, and the foreground image comprises a high-frequency signal image; a first processing unit, for fitting the grayscale values of each pixel in each row of the image to be processed by the least squares method to obtain a quadratic function to obtain a row grayscale distribution function of each row, and fitting the grayscale values of each pixel in each column of the image to be processed by the least squares method to obtain a quadratic function to obtain a column grayscale distribution function of each column; a determination unit, for correcting the actual grayscale values of each pixel in each row of the image to be processed by using each of the row grayscale distribution functions to obtain a row threshold image of the image to be processed, and correcting the actual grayscale values of each pixel in each column of the image to be processed by using each of the column grayscale distribution functions to obtain a column threshold image of the image to be processed; and a second processing unit, for fusing the row threshold image and the column threshold image to obtain the foreground image.
[0013] According to another aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute any one of the image segmentation methods.
[0014] According to another aspect of the present application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include a method for executing any one of the image segmentation methods.
[0015] Applying the technical solution of the present application, the above-mentioned image segmentation method based on the least squares method first inputs the image to be processed, the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image; the least squares method is used to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, and the least squares method is used to fit the grayscale values of each pixel in each column of the image to be processed to obtain a quadratic function to obtain a column grayscale distribution function of each column; the actual grayscale values of each pixel in each row of the image to be processed are corrected by the grayscale distribution functions of each row to obtain a row threshold image of the image to be processed, and the actual grayscale values of each pixel in each column of the image to be processed are corrected by the grayscale distribution functions of each column to obtain a column threshold image that determines the image to be processed; finally, the row threshold image and the column threshold image are fused to obtain the foreground image. This method can process the least squares row and column thresholds more accurately, can maximize the guarantee that it will not be disturbed by the uneven background area, reduce subsequent calculations, and use the additive fusion method to fuse the row threshold image with the column threshold image, which can solve the problem that the threshold in a single direction cannot completely segment the target, ensure the integrity of the segmented target, and solve the problem that the existing image segmentation method cannot accurately segment the foreground image when targeting high-frequency signal targets. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings constituting part of the present application are used to provide a further understanding of the present application. The exemplary embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0017] Figure 1 A hardware structure block diagram of a mobile terminal according to an image segmentation method provided in an embodiment of the present application is shown;
[0018] Figure 2 A schematic diagram of a process of an image segmentation method provided in an embodiment of the present application is shown;
[0019] Figure 3 (a)-(b) are schematic diagrams showing the effect of extracting a target as a central cross image according to an embodiment of the present application;
[0020] Figure 4 (a)-(b) are schematic diagrams showing the effect of extracting a circle and a cross as targets according to an embodiment of the present application;
[0021] Figure 5 (a)-(c) are schematic diagrams showing the effect of an image segmentation method provided in an embodiment of the present application;
[0022] Figure 6A schematic diagram of a process flow of another image segmentation method provided according to an embodiment of the present application is shown;
[0023] Figure 7 A structural block diagram of another image segmentation device provided according to an embodiment of the present application is shown.
[0024] The above drawings include the following reference numerals:
[0025] 102, processor; 104, memory; 106, transmission device; 108, input and output devices. DETAILED DESCRIPTION
[0026] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0027] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] As introduced in the background technology, in the prior art, a global threshold method is used to calculate the maximum and minimum grayscale values of the entire image as a range, and calculate the maximum inter-class difference corresponding to each grayscale value within this range. Then, the relationship curve between the grayscale range and the maximum inter-class difference is fitted using the least squares method, and a maximum value is calculated based on the curve. The grayscale value corresponding to this maximum value is the threshold value, which is used to binarize the image. In order to solve the problem that the existing image segmentation method cannot accurately segment the foreground image for high-frequency signal targets, the embodiments of the present application provide an image segmentation method, an image segmentation device, a computer-readable storage medium, and an electronic device.
[0030] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0031] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 1 is a hardware structure block diagram of a mobile terminal of an image segmentation method based on the least squares method according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is for illustration only and does not limit the structure of the mobile terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0032] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the Z method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, the above method is implemented. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above-mentioned network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof. The transmission device 106 is used to receive or send data via a network. The above-mentioned specific examples of the network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0033] In this embodiment, an image segmentation method running on a mobile terminal, a computer terminal or a similar computing device is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0034] Figure 2 FIG. 1 is a flow chart of an image segmentation method according to an embodiment of the present application. Figure 2 As shown, the method comprises the following steps:
[0035] Step S201, inputting an image to be processed, wherein the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image;
[0036] Specifically, the images to be processed are mainly images with uneven backgrounds and targets with high-frequency signals.
[0037] In some instances, such as Figure 3 (a) and Figure 4 The two images shown in (a) represent images to be processed with uneven backgrounds and high-frequency signals as the targets to be extracted. Figure 3 The target extracted in (a) is a cross. Figure 4 The extracted regions in (a) are circles and crosses.
[0038] After inputting the image to be processed, and before using the least squares method to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, the method further includes: performing median filtering on the image to be processed to eliminate noise in the image to be processed, wherein the size of the filter kernel is 5×5 pixels.
[0039] Specifically, move the 5×5 pixel filter kernel from left to right and from top to bottom on the image to be processed. For each pixel, sort the pixel values of the surrounding 5×5 pixels by size and find the middle value. Use the median value as the new pixel value of the pixel. Continue to move the filter kernel until the entire image is processed. Through median filtering, the noise in the image can be effectively eliminated while retaining the edge information of the image, resulting in a clearer and smoother image.
[0040] Step S202, using the least squares method to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, and using the least squares method to fit the grayscale values of each pixel in each column of the image to be processed to obtain a quadratic function to obtain a column grayscale distribution function of each column;
[0041] Specifically, for the grayscale value of the pixel in each row, it can be regarded as the input variable of a quadratic function, that is, the x-coordinate, and the grayscale value is the y-coordinate. The least squares method can be used to fit these data points to obtain a quadratic function that represents the grayscale distribution of the row. Similarly, for the grayscale values of the pixels in each column, we can also perform the same operation to obtain the column grayscale distribution function of each column. A loss function can be defined, and then the loss function can be derived using the least squares method. In this way, we can obtain the grayscale distribution function of each row and column, so as to better maximize the guarantee that it will not be interfered by the uneven background area and reduce subsequent calculations;
[0042] The least square method is used to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, including the following steps:
[0043] Step 2021, obtaining the grayscale values of all pixels in the current row of the image to be processed, and storing them in a first array in a first order;
[0044] Step 2022, converting each data in the first array into corresponding two-dimensional coordinate data, wherein each two-dimensional coordinate data is composed of x and y, wherein x represents the order of the pixel points corresponding to the two-dimensional coordinate data, and y represents the actual grayscale value of the pixel points corresponding to the two-dimensional coordinate data;
[0045] Step 2023, using the least squares method to fit each of the above two-dimensional coordinate data to obtain the above row grayscale distribution function.
[0046] Specifically, the data in the array is converted into two-dimensional coordinate data. In the coordinate data, x is edited according to the data order of 1, 2, 3, ..., n, and y is the corresponding data. The two-dimensional coordinate data is fitted using the least squares method to fit the grayscale value of the pixel. The above steps can better understand the grayscale changes of each part of the image and lay a data foundation for subsequent image processing and analysis.
[0047] The least square method is used to fit the above two-dimensional coordinate data to obtain the above row grayscale distribution function, including the following steps: defining the above row grayscale distribution function as y θ =θ0+θ1x1+θ2x2+……+θ n x n ; Determine the loss function Among them, j is the difference between the actual gray value of the above pixel and the fitted gray value, h θ is the fitting gray value of the above pixel points, m is the total number of rows of the above image to be processed, x is the serial number of the above pixel point, y is the actual gray value of the above pixel point, θ is the function coefficient of the gray distribution function of the above row, θ n is the nth coefficient in the grayscale distribution function, n is the feature dimension; according to the above loss function, the function coefficient θ=(X T X) -1 X T Y, and determine the above-mentioned row grayscale distribution function based on the above-mentioned function coefficients.
[0048] Specifically, using the least square method to divide the row and column thresholds can maximize the guarantee that there will be no interference from the background uneven area, reducing subsequent calculations.
[0049] In some examples, starting from the first row, all pixel values of the current row are obtained and stored in an array from left to right; the data in the array is converted into two-dimensional coordinate data, and x in the coordinate data is edited according to the data order of 1, 2, 3, ..., n, and y is each corresponding data. Then, the least squares method is used to fit the two-dimensional coordinate data. The fitting method is as follows:
[0050] Assume the function is: θ =θ0+θ1x1+θ2x2+……+θ n x n , expressed in matrix form as: Y = Xθ;
[0051] in: m represents the number of samples, n is the feature dimension, in this embodiment, m is the number of rows / columns of the image, which is also equal to the width / height of the input image. Because the fitting function in this embodiment is a second-order function, n is equal to 3, and its loss function is: According to the least squares method, the loss function can be derived into formula 1:
[0052]
[0053] Let formula 1 be 0, and we can get formula 2:
[0054] X T Xθ=X T Y (Formula 2)
[0055] According to formula 2, the function coefficient θ can be calculated as follows: T X) -1 X T Y.
[0056] Step S203, using each of the above-mentioned row grayscale distribution functions to correct the actual grayscale value of each pixel in each row of the above-mentioned image to be processed, so as to obtain a row threshold image of the above-mentioned image to be processed, and using each of the above-mentioned column grayscale distribution functions to correct the actual grayscale value of each pixel in each column of the above-mentioned image to be processed, so as to obtain a column threshold image of the above-mentioned image to be processed;
[0057] Specifically, for each row, count the number of pixels of each grayscale value in the row to obtain the grayscale distribution function of the row. According to the row grayscale distribution function, correct the actual grayscale value of each pixel to obtain the row threshold image. For each column, similarly count the number of pixels of each grayscale value in the column to obtain the grayscale distribution function of the column. According to the column grayscale distribution function, correct the actual grayscale value of each pixel to obtain the column threshold image. Through the above steps, we can obtain the row threshold image and column threshold image after being corrected by the row grayscale distribution function and the column grayscale distribution function.
[0058] The method of using the above-mentioned row grayscale distribution functions to correct the actual grayscale value of each pixel in each row of the above-mentioned image to be processed to obtain the row threshold image of the above-mentioned image to be processed includes the following steps:
[0059] Step S2031, obtaining the threshold coefficient of each row of the above-mentioned image to be processed;
[0060] Step S2032: Determine the fitting grayscale value of each pixel in the current row according to the above row grayscale distribution function. Among them, x i is the position of the i-th pixel in the current row;
[0061] Step S2033, determining the product of the fitting gray value and the threshold coefficient as the gray threshold of the pixel point;
[0062] Step S2034, determining the row threshold image according to the actual grayscale value of the pixel point and the corresponding grayscale threshold.
[0063] Specifically, the least squares method is used to fit the distribution function to generate corresponding row threshold images and column threshold images, which can maximize the guarantee that they will not be disturbed by uneven background areas and reduce subsequent calculations. In subsequent processing, the row threshold image and the column threshold image are added and fused into one image, making the extracted target more complete.
[0064] In some embodiments, the threshold T is calculated according to a fitted function, where In the formula, x i is the position of the i-th pixel in the current row, T i is the threshold corresponding to the position of the i-th pixel in the current row, and d is the threshold coefficient, which is a constant.
[0065] According to the actual gray value of the pixel point and the corresponding gray threshold value, determining the row threshold image includes the following steps:
[0066] Step S301: when the actual grayscale value of the foreground image is greater than the actual grayscale value of the background image, according to the first formula Determine the grayscale value of the pixel in the row threshold image, where g(x i ) is the gray value of the above pixel in the above row threshold image, x i is the i-th pixel point in the current row, y i is the gray value of the i-th pixel in the above image to be processed, T i is the grayscale threshold corresponding to the i-th pixel;
[0067] Step S302: when the actual grayscale value of the foreground image is less than the actual grayscale value of the background image, the grayscale value of the foreground image is calculated according to the second formula: Determine the grayscale value of the pixel in the row threshold image;
[0068] Step S303: determining the row threshold image according to the grayscale value of each pixel in the row threshold image.
[0069] Specifically, the grayscale value of each pixel in the corresponding threshold image can be assigned according to the actual grayscale value of each pixel, so as to binarize each pixel, thereby obtaining the corresponding row threshold image and column threshold image. And for the two situations where the extraction target is lower or higher than the background grayscale, different binarization strategies are performed to obtain the row threshold image and column threshold image that are more suitable for the current scene.
[0070] The first formula is applied to the scene where the grayscale of the extracted target is higher than that of the background, and the second formula is applied to the scene where the grayscale of the extracted target is lower than that of the background.
[0071] In this embodiment, the pixel value of the image ranges from 0 to 2 8 -1, that is, the threshold of 0 to 255 can also be called binarization, that is, the image is processed into a binary image through the threshold, that is, there are only two values 0 (black) and 255 (white).
[0072] The image column direction threshold method is roughly the same as the row direction threshold method, except that the grayscale of each column of pixels is obtained as the coordinate y value for calculation. The acquisition process of the column threshold image is not described in detail here.
[0073] Step S204: Fusing the row threshold image and the column threshold image to obtain the foreground image.
[0074] Specifically, the row threshold image and the column threshold image are merged by the additive fusion method because the threshold in a single direction cannot completely segment the target. If the threshold images in each direction are fused, the integrity of the segmented target can be guaranteed.
[0075] In some instances, Figure 5 (a)-(c) are schematic diagrams showing the effect of an image segmentation method. Figure 5 (a) is the row threshold image, Figure 5 (b) is the column threshold image, Figure 5 (c) is the foreground image obtained by fusing the row threshold image and the column threshold image. Figure 5 As shown in (a)-(c), the row threshold image and the column threshold image are fused by the additive fusion method, and the threshold images in each direction can be fused to ensure the integrity of the segmented target.
[0076] The step of fusing the row threshold image and the column threshold image to obtain the foreground image comprises the following steps:
[0077] Step S2041, determining the sum of the grayscale value of the pixel point in the row threshold image and the grayscale value of the pixel point in the column threshold image as the intermediate grayscale value;
[0078] Step S2042, when the intermediate gray value is greater than or equal to 255, the gray value of the pixel in the foreground image is determined to be 255; when the intermediate gray value is less than 255, the gray value of the pixel in the foreground image is determined to be 0;
[0079] Step S2043, determining the foreground image according to the grayscale value of each of the above pixels in the foreground image.
[0080] Specifically, the method determines the row threshold image according to the actual grayscale value of the above-mentioned pixel and the size of the corresponding grayscale threshold, which means determining the grayscale value of the pixel in the foreground image according to the grayscale value of each pixel in the row threshold image. The specific steps include calculating the sum of the grayscale values of each pixel in the row threshold image and the column threshold image, and taking it as the intermediate grayscale value. If the intermediate grayscale value is greater than or equal to 255, the grayscale value of the pixel in the foreground image is set to 255; if the intermediate grayscale value is less than 255, the grayscale value of the pixel in the foreground image is set to 0. Finally, the formation of the foreground image is determined according to the grayscale values of all pixels in the foreground image. In this way, it can be determined that the row threshold image can better extract the target object in the image, reduce the interference of noise, improve the quality and clarity of the image, and thus better support subsequent image processing and analysis work.
[0081] In some instances, after the row and column thresholds are completed, due to the random size and orientation of the target, the row threshold image and the column threshold image may only segment part of the target area. If the complete target is required, the two images need to be fused into one image. The fusion formula is: fuse (x,y)=I row (x,y)+I col (x,y). fuse (x, y) is the gray value of the pixel (x, y) in the fused image. fuse When (x, y) is greater than 255, set its value to 255. fuse When (x,y) is equal to 255, its value is 255, I fuse When (x, y) is equal to 0, its value is 0; I row (x, y) is the gray value of the pixel (x, y) in the row threshold image, I col (x,y) is the grayscale value of pixel (x,y) in the column threshold image.
[0082] In some instances, Figure 3 (a)-(b) is a schematic diagram of the effect of extracting a cross image with the target as the center. Figure 4 (a)-(b) are schematic diagrams of the effect of extracting a circle and a cross as the target. Figure 3 As shown in (a)-(b), Figure 3 (a) is the image to be processed with an uneven background and a high-frequency target signal. Figure 3 (b) is the foreground image (center cross image) extracted using the above image segmentation method. Figure 4 As shown in (a)-(b), Figure 4 (a) is the image to be processed with an uneven background and a high-frequency target signal. Figure 4 (b) is the foreground image (circle and cross image) extracted by the above image segmentation method. Figure 3 and Figure 4 It can be seen that the threshold segmentation method based on the least squares method can completely segment the target with good results.
[0083] Through this embodiment, the least square method row and column thresholds can be processed more accurately, which can maximize the guarantee that there will be no interference from the background uneven area, reduce subsequent calculations, and use the addition fusion method to fuse the row threshold image with the column threshold image, which can solve the problem that the threshold in a single direction cannot completely segment the target, and ensure the integrity of the segmented target. The problem that the existing image segmentation method cannot accurately segment the foreground image for high-frequency signal targets is solved.
[0084] The above-mentioned image segmentation method of the present application first inputs an image to be processed, the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image; the least squares method is used to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, and the least squares method is used to fit the grayscale values of each pixel in each column of the image to be processed to obtain a quadratic function to obtain a column grayscale distribution function of each column; the actual grayscale values of each pixel in each row of the image to be processed are corrected by the grayscale distribution functions of each row to obtain a row threshold image of the image to be processed, and the actual grayscale values of each pixel in each column of the image to be processed are corrected by the grayscale distribution functions of each column to obtain a column threshold image that determines the image to be processed; finally, the row threshold image and the column threshold image are fused to obtain a foreground image. This method can process the least squares row and column thresholds more accurately, can maximize the guarantee that it will not be disturbed by the uneven background area, reduce subsequent calculations, and use the additive fusion method to fuse the row threshold image with the column threshold image, which can solve the problem that the threshold in a single direction cannot completely segment the target, ensure the integrity of the segmented target, and solve the problem that the existing image segmentation method cannot accurately segment the foreground image when targeting high-frequency signal targets.
[0085] In order to enable those skilled in the art to more clearly understand the technical solution of the present application, the implementation process of the image segmentation method of the present application will be described in detail below in conjunction with specific embodiments.
[0086] This embodiment relates to a specific image segmentation method based on the least squares method, such as Figure 6 As shown, the following steps are included:
[0087] Step S1: Input an image. The processed image is mainly an image with an uneven background and a target of a high-frequency signal;
[0088] Step S2: median filtering is performed on the input image. The filter kernel size is set according to the actual situation. In this embodiment, the filter kernel size is set to 5×5 pixels, which is mainly used to eliminate noise in the image.
[0089] Step S3: Get row data, and use the least squares method to fit the grayscale change function, calculate the corresponding fitting value of the row data point, and set the threshold coefficient to determine whether the actual grayscale value of the current pixel is greater than / less than the threshold (when the target grayscale is higher than the background grayscale, determine whether the actual grayscale value of the current pixel is greater than the threshold; when the target grayscale is lower than the background grayscale, determine whether the actual grayscale value of the current pixel is less than the threshold). If yes, mark the grayscale value of the current pixel as 255, otherwise, mark the grayscale value of the current pixel as 0, and then determine whether the current pixel is the last point of the row. If not, continue to calculate the next corresponding fitting value. If yes, determine whether the current row is the last row. If not, continue to obtain the row data of the next row. If yes, then declare a row threshold image;
[0090] Step S4: Get the column data, and use the least square method to fit the grayscale change function, calculate the corresponding fitting value of the column data point, and set the threshold coefficient to determine whether the actual grayscale value of the current pixel is greater than / less than the threshold (when the target grayscale is higher than the background grayscale, determine whether the actual grayscale value of the current pixel is greater than the threshold; when the target grayscale is lower than the background grayscale, determine whether the actual grayscale value of the current pixel is less than the threshold). If yes, mark the grayscale value of the current pixel as 255, otherwise, mark the grayscale value of the current pixel as 0, and then determine whether the current pixel is the last point in this column. If not, continue to calculate the next corresponding fitting value. If yes, determine whether the current column is the last column. If not, continue to obtain the column data of the next column. If yes, then generate a column threshold image.
[0091] Step S5: Fusing the row threshold image with the column threshold image to output a final fused threshold image.
[0092] The embodiment of the present application also provides an image segmentation device. It should be noted that the image segmentation device of the embodiment of the present application can be used to execute the image segmentation method provided by the embodiment of the present application. The device is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions thereof will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0093] The following is an introduction to the image segmentation device provided in the embodiments of the present application.
[0094] Figure 7 is a schematic diagram of an image segmentation device according to an embodiment of the present application. Figure 7As shown, the device includes: an input unit 10, a first processing unit 20, a determination unit 30 and a second determination unit 40, the input unit 10 is used to input the image to be processed, the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image; the first processing unit 20 is used to fit the grayscale value of each pixel in each row of the image to be processed by the least squares method to obtain a quadratic function to obtain a row grayscale distribution function of each row, and to fit the grayscale value of each pixel in each column of the image to be processed by the least squares method to obtain a quadratic function to obtain a column grayscale distribution function of each column; the determination unit 30 is used to correct the actual grayscale value of each pixel in each row of the image to be processed by using each of the above-mentioned row grayscale distribution functions to obtain the row threshold image of the image to be processed, and to correct the actual grayscale value of each pixel in each column of the image to be processed by using each of the above-mentioned column grayscale distribution functions to obtain the column threshold image of the image to be processed; the second processing unit 40 is used to merge the above-mentioned row threshold image and the above-mentioned column threshold image to obtain the above-mentioned foreground image.
[0095] The above-mentioned image segmentation device of the present application includes: an input unit, a first processing unit, a determination unit and a second determination unit, the input unit is used to input the image to be processed, the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image; the first processing unit is used to use the least squares method to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function, so as to obtain a row grayscale distribution function of each row, and use the least squares method to fit the grayscale values of each pixel in each column of the image to be processed to obtain a quadratic function, so as to obtain a column grayscale distribution function of each column; the determination unit is used to use the grayscale distribution functions of each row to correct the actual grayscale values of each pixel in each row of the image to be processed to obtain a row threshold image of the image to be processed, and use the grayscale distribution functions of each column to correct the actual grayscale values of each pixel in each column of the image to be processed to obtain a column threshold image of the image to be processed; the second processing unit is used to merge the above-mentioned row threshold image and the above-mentioned column threshold image to obtain the above-mentioned foreground image. The device can process the least squares method row and column thresholds more accurately, can maximize the guarantee that it will not be disturbed by the background uneven area, reduce subsequent calculations, and use the additive fusion method to fuse the row threshold image with the column threshold image, which can solve the problem that the threshold in a single direction cannot completely segment the target, ensure the integrity of the segmented target, and solve the problem that the existing image segmentation method cannot accurately segment the foreground image when targeting high-frequency signal targets.
[0096] In some examples, the first processing unit includes a first acquisition module, a first conversion module and a first fitting module. The first acquisition module is used to obtain the grayscale values of all pixels in the current row of the above-mentioned image to be processed, and store them in the first array according to the first order. The first conversion module is used to convert each data in the above-mentioned first array into corresponding two-dimensional coordinate data, and one of the above-mentioned two-dimensional coordinate data consists of x and y, wherein x represents the order of the above-mentioned pixels corresponding to the above-mentioned two-dimensional coordinate data, and y represents the actual grayscale value of the above-mentioned pixel corresponding to the above-mentioned two-dimensional coordinate data; the first fitting module is used to fit each of the above-mentioned two-dimensional coordinate data using the least squares method to obtain the above-mentioned row grayscale distribution function. In this way, the grayscale changes of each part of the image can be better understood, which provides help for subsequent image processing and analysis.
[0097] In some examples, the first fitting module includes a first processing submodule, a first determining submodule and a second determining submodule, wherein the first processing submodule is used to define the above-mentioned row grayscale distribution function as y θ =θ0+θ1x1+θ2x2+……+θ n x n ; The first determination submodule is used to determine the loss function Among them, j is the difference between the actual gray value of the above pixel and the fitted gray value, h θ is the fitting gray value of the above pixel points, m is the total number of rows of the above image to be processed, x is the serial number of the above pixel point, y is the actual gray value of the above pixel point, θ is the function coefficient of the gray distribution function of the above row, θ n is the nth coefficient in the grayscale distribution function, where n is the feature dimension; the second determination submodule is used to determine the function coefficient θ=(X T X) -1 X T Y, and determine the above-mentioned row grayscale distribution function according to the above-mentioned function coefficients. This can better understand the grayscale changes of each part of the image and provide help for subsequent image processing and analysis.
[0098] In some examples, the determination unit includes a first processing module, a second processing module, a third processing module and a fourth processing module, the first processing module is used to obtain the threshold coefficient of each row of the above-mentioned image to be processed; the second processing module is used to determine the fitting gray value of each pixel point in the current row according to the above-mentioned row gray distribution function. Among them, x iis the position of the i-th pixel in the current row; the third processing module is used to determine the grayscale threshold of the pixel by multiplying the above-mentioned fitting grayscale value by the above-mentioned threshold coefficient; the fourth processing module is used to determine the row threshold image according to the actual grayscale value of the pixel and the corresponding grayscale threshold. In this way, it can be guaranteed to be free from interference from the background uneven area to the greatest extent, reducing subsequent calculations.
[0099] In some examples, the fourth processing module includes a third determining submodule, a fourth determining submodule and a fifth determining submodule, wherein the third determining submodule is used for determining, according to the first formula, when the actual gray value of the foreground image is greater than the actual gray value of the background image. Determine the grayscale value of the pixel in the row threshold image, where g(x i ) is the gray value of the above pixel in the above row threshold image, x i is the i-th pixel point in the current row, y i is the gray value of the i-th pixel in the above image to be processed, T i is the grayscale threshold corresponding to the i-th pixel; the fourth determination submodule is used to determine the grayscale value of the foreground image according to the second formula when the actual grayscale value of the foreground image is less than the actual grayscale value of the background image. Determine the grayscale value of the above pixel point in the above row threshold image; the fifth determination submodule is used to determine the above row threshold image according to the grayscale value of each pixel point in the above row threshold image. In this way, the grayscale value of each pixel point in the corresponding threshold image can be assigned according to the actual grayscale value of each pixel point, so as to binarize each pixel point, thereby obtaining the corresponding row threshold image and column threshold image.
[0100] In some instances, the second processing unit includes a first determination module, a second determination module and a third determination module. The first determination module is used to determine the sum of the grayscale value of the above-mentioned pixel point in the above-mentioned row threshold image and the grayscale value of the above-mentioned pixel point in the above-mentioned column threshold image as an intermediate grayscale value; the second determination module is used to determine the grayscale value of the above-mentioned pixel point in the above-mentioned foreground image as 255 when the above-mentioned intermediate grayscale value is greater than or equal to 255, and to determine the grayscale value of the above-mentioned pixel point in the above-mentioned foreground image as 0 when the above-mentioned intermediate grayscale value is less than 255; the third determination module is used to determine the above-mentioned foreground image according to the grayscale value of each of the above-mentioned pixel points in the above-mentioned foreground image. In this way, it can be determined that the row threshold image can better extract the target object in the image and reduce the interference of noise.
[0101] In some examples, the device further includes a fifth processing module, which is used to perform median filtering on the image to be processed after inputting the image to be processed and before fitting the grayscale values of each pixel in each row of the image to be processed using the least squares method to obtain a quadratic function to obtain a row grayscale distribution function of each row, so as to eliminate noise in the image to be processed, wherein the size of the filter kernel is 5×5 pixels. This method is better for eliminating noise in images.
[0102] The image segmentation device includes a processor and a memory, the input unit and the like are stored in the memory as program units, and the processor executes the program units stored in the memory to implement corresponding functions. The modules are all located in the same processor; or, the modules are located in different processors in any combination.
[0103] The processor includes a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and the problem that the existing image segmentation method cannot accurately segment the foreground image for high-frequency signal targets can be solved by adjusting the kernel parameters.
[0104] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0105] An embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the image segmentation method.
[0106] Specifically, the method for determining the image segmentation method includes:
[0107] Step S201, inputting an image to be processed, wherein the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image;
[0108] Step S202, using the least squares method to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, and using the least squares method to fit the grayscale values of each pixel in each column of the image to be processed to obtain a quadratic function to obtain a column grayscale distribution function of each column;
[0109] Step S203, using the row grayscale distribution function to correct the actual grayscale value of each pixel in each row of the image to be processed, to obtain a row threshold image of the image to be processed, and using the column grayscale distribution function to correct the actual grayscale value of each pixel in each column of the image to be processed, to obtain a column threshold image of the image to be processed;
[0110] Step S204: Fusing the row threshold image and the column threshold image to obtain the foreground image.
[0111] An embodiment of the present invention provides a processor, and the processor is used to run a program, wherein the image segmentation method is executed when the program is run.
[0112] Specifically, the method for determining the image segmentation method includes:
[0113] Step S201, inputting an image to be processed, wherein the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image;
[0114] Step S202, using the least squares method to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, and using the least squares method to fit the grayscale values of each pixel in each column of the image to be processed to obtain a quadratic function to obtain a column grayscale distribution function of each column;
[0115] Step S203, using the row grayscale distribution function to correct the actual grayscale value of each pixel in each row of the image to be processed, to obtain a row threshold image of the image to be processed, and using the column grayscale distribution function to correct the actual grayscale value of each pixel in each column of the image to be processed, to obtain a column threshold image of the image to be processed;
[0116] Step S204: Fusing the row threshold image and the column threshold image to obtain the foreground image.
[0117] An embodiment of the present invention provides a device, the device including a processor, a memory, and a program stored in the memory and executable on the processor, and when the processor executes the program, at least the following steps are implemented:
[0118] Step S201, inputting an image to be processed, wherein the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image;
[0119] Step S202, using the least squares method to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, and using the least squares method to fit the grayscale values of each pixel in each column of the image to be processed to obtain a quadratic function to obtain a column grayscale distribution function of each column;
[0120] Step S203, using the row grayscale distribution function to correct the actual grayscale value of each pixel in each row of the image to be processed, to obtain a row threshold image of the image to be processed, and using the column grayscale distribution function to correct the actual grayscale value of each pixel in each column of the image to be processed, to obtain a column threshold image of the image to be processed;
[0121] Step S204: Fusing the row threshold image and the column threshold image to obtain the foreground image.
[0122] The devices in this article can be servers, PCs, PADs, mobile phones, etc.
[0123] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program for initializing at least the following method steps:
[0124] Step S201, inputting an image to be processed, wherein the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image;
[0125] Step S202, using the least squares method to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, and using the least squares method to fit the grayscale values of each pixel in each column of the image to be processed to obtain a quadratic function to obtain a column grayscale distribution function of each column;
[0126] Step S203, using the row grayscale distribution function to correct the actual grayscale value of each pixel in each row of the image to be processed, to obtain a row threshold image of the image to be processed, and using the column grayscale distribution function to correct the actual grayscale value of each pixel in each column of the image to be processed, to obtain a column threshold image of the image to be processed;
[0127] Step S204: Fusing the row threshold image and the column threshold image to obtain the foreground image.
[0128] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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 device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing 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.
[0129] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising 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.
[0130] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing 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.
[0131] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0132] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0133] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0134] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0135] From the above description, it can be seen that the above embodiments of the present application achieve the following technical effects:
[0136] 1) The above-mentioned image segmentation method of the present application first inputs the image to be processed, the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image; the least squares method is used to fit the grayscale values of each pixel in each row of the image to be processed to obtain a quadratic function to obtain a row grayscale distribution function of each row, and the least squares method is used to fit the grayscale values of each pixel in each column of the image to be processed to obtain a quadratic function to obtain a column grayscale distribution function of each column; the actual grayscale values of each pixel in each row of the image to be processed are corrected by the grayscale distribution functions of each row to obtain a row threshold image of the image to be processed, and the actual grayscale values of each pixel in each column of the image to be processed are corrected by the grayscale distribution functions of each column to obtain a column threshold image of the image to be processed; finally, the row threshold image and the column threshold image are fused to obtain a foreground image. This method can process the least squares row and column thresholds more accurately, can maximize the guarantee that it will not be disturbed by the uneven background area, reduce subsequent calculations, and use the additive fusion method to fuse the row threshold image with the column threshold image, which can solve the problem that the threshold in a single direction cannot completely segment the target, ensure the integrity of the segmented target, and solve the problem that the existing image segmentation method cannot accurately segment the foreground image when targeting high-frequency signal targets.
[0137] 2) The image segmentation device of the present application comprises: an input unit, a first processing unit, a determination unit and a second determination unit, the input unit is used to input the image to be processed, the image to be processed comprises a foreground image and a background image, and the foreground image comprises a high-frequency signal image; the first processing unit is used to fit the grayscale values of each pixel in each row of the image to be processed by the least squares method to obtain a quadratic function to obtain a row grayscale distribution function of each row, and to fit the grayscale values of each pixel in each column of the image to be processed by the least squares method to obtain a quadratic function to obtain a column grayscale distribution function of each column; the determination unit is used to correct the actual grayscale values of each pixel in each row of the image to be processed by the grayscale distribution functions of each row to obtain a row threshold image of the image to be processed, and to correct the actual grayscale values of each pixel in each column of the image to be processed by the grayscale distribution functions of each column to obtain a column threshold image of the image to be processed; the second processing unit is used to fuse the above-mentioned row threshold image and the above-mentioned column threshold image to obtain the above-mentioned foreground image. The device can process the least squares method row and column thresholds more accurately, can maximize the guarantee that it will not be disturbed by the background uneven area, reduce subsequent calculations, and use the additive fusion method to fuse the row threshold image with the column threshold image, which can solve the problem that the threshold in a single direction cannot completely segment the target, ensure the integrity of the segmented target, and solve the problem that the existing image segmentation method cannot accurately segment the foreground image when targeting high-frequency signal targets.
[0138] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. An image segmentation method, characterized in that: include: Inputting an image to be processed, wherein the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image; The grayscale values of each pixel in each row of the image to be processed are fitted by the least squares method to obtain a quadratic function to obtain a row grayscale distribution function of each row, and the grayscale values of each pixel in each column of the image to be processed are fitted by the least squares method to obtain a quadratic function to obtain a column grayscale distribution function of each column; Using each of the row grayscale distribution functions to correct the actual grayscale value of each pixel in each row of the image to be processed, so as to obtain a row threshold image of the image to be processed, and using each of the column grayscale distribution functions to correct the actual grayscale value of each pixel in each column of the image to be processed, so as to obtain a column threshold image of the image to be processed; The row threshold image and the column threshold image are fused to obtain the foreground image.
2. The method according to claim 1, characterized in that The grayscale value of each pixel in each row of the image to be processed is fitted by the least square method to obtain a quadratic function to obtain a row grayscale distribution function of each row, including: Obtaining the grayscale values of all pixels in the current row of the image to be processed, and storing them in a first array in a first order; Convert each data in the first array into corresponding two-dimensional coordinate data, wherein each two-dimensional coordinate data is composed of x and y, wherein x represents the order of the pixel points corresponding to the two-dimensional coordinate data, and y represents the actual grayscale value of the pixel points corresponding to the two-dimensional coordinate data; The least square method is used to fit each of the two-dimensional coordinate data to obtain the row grayscale distribution function.
3. The method according to claim 2, characterized in that The least square method is used to fit each of the two-dimensional coordinate data to obtain the row grayscale distribution function, including: Define the row grayscale distribution function as y θ =θ0+θ1x1+θ2x2+……+θ n x n ; Determine the loss function Wherein, j is the difference between the actual grayscale value of the pixel and the fitted grayscale value, h θ is the fitting grayscale value of the pixel point being fitted, m is the total number of rows of the image to be processed, x is the sequence number of the pixel, y is the actual gray value of the pixel, θ is the function coefficient of the row gray distribution function, θ n is the nth coefficient in the grayscale distribution function, where n is the feature dimension; According to the loss function, the function coefficient θ=(X T X) -1 X T Y, and determine the row grayscale distribution function according to the function coefficient.
4. The method according to claim 1, characterized in that: The actual grayscale value of each pixel in each row of the image to be processed is corrected by using each of the row grayscale distribution functions to obtain a row threshold image of the image to be processed, including: Obtaining the threshold coefficient of each row of the image to be processed; According to the row grayscale distribution function, the fitting grayscale value of each pixel in the current row is determined Among them, x i is the position of the i-th pixel in the current row, and a, b, and c are constants; Determine the product of the fitting grayscale value and the threshold coefficient as the grayscale threshold of the pixel point; The row threshold image is determined according to the actual grayscale value of the pixel and the corresponding grayscale threshold.
5. The method according to claim 4, characterized in that Determining the row threshold image according to the actual grayscale value of the pixel and the corresponding grayscale threshold, including: When the actual grayscale value of the foreground image is greater than the actual grayscale value of the background image, according to the first formula Determine the grayscale value of the pixel in the row threshold image, where g(xi) is the grayscale value of the pixel in the row threshold image, x i is the i-th pixel of the current row, y i is the gray value of the i-th pixel in the image to be processed, T i is the grayscale threshold corresponding to the i-th pixel; When the actual grayscale value of the foreground image is less than the actual grayscale value of the background image, according to the second formula Determine the grayscale value of the pixel in the row threshold image; The row threshold image is determined according to the grayscale value of each pixel in the row threshold image.
6. The method according to claim 1, characterized in that The row threshold image and the column threshold image are fused to obtain the foreground image, including: Determine the sum of the grayscale value of the pixel point in the row threshold image and the grayscale value of the pixel point in the column threshold image as an intermediate grayscale value; When the intermediate gray value is greater than or equal to 255, the gray value of the pixel in the foreground image is determined to be 255; when the intermediate gray value is less than 255, the gray value of the pixel in the foreground image is determined to be 0; The foreground image is determined according to the grayscale value of each pixel in the foreground image.
7. The method according to claim 1, characterized in that After inputting the image to be processed and before fitting the grayscale values of each pixel in each row of the image to be processed by the least square method to obtain a quadratic function to obtain a row grayscale distribution function of each row, the method further includes: A median filter is performed on the image to be processed to eliminate noise in the image to be processed, wherein the size of the filter kernel is 5×5 pixels.
8. An image segmentation device, characterized in that: include: An input unit, used for inputting an image to be processed, wherein the image to be processed includes a foreground image and a background image, and the foreground image includes a high-frequency signal image; A first processing unit is used to fit the grayscale values of each pixel in each row of the image to be processed by using the least squares method to obtain a quadratic function to obtain a row grayscale distribution function of each row, and to fit the grayscale values of each pixel in each column of the image to be processed by using the least squares method to obtain a quadratic function to obtain a column grayscale distribution function of each column; A determination unit, configured to correct the actual grayscale value of each pixel in each row of the image to be processed by using each of the row grayscale distribution functions to obtain a row threshold image of the image to be processed, and to correct the actual grayscale value of each pixel in each column of the image to be processed by using each of the column grayscale distribution functions to obtain a column threshold image of the image to be processed; The second processing unit is used to fuse the row threshold image and the column threshold image to obtain the foreground image.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the image segmentation method according to any one of claims 1 to 7.
10. An electronic device, characterized in that: include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include a method for executing the image segmentation method described in any one of claims 1 to 7.
Citation Information
Cited By
Image segmentation method, electronic device, storage medium and program product
CN121190514A
