Method for calculating boundary perimeter of region of interest in high-resolution image
Through parallel processing and iterative algorithms, the boundary perimeter of the region of interest in high-resolution images is calculated, which solves the problems of low computing efficiency and limited accuracy in the prior art, and realizes efficient and accurate perimeter calculation.
Patent Information
- Application Number
- CN202411907099.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2044-12-23
AI Technical Summary
The prior art, when calculating the boundary perimeter of the region of interest in high-resolution images, has low computing efficiency, unstable results, limited calculation accuracy, and limited noise sensitivity and applicability.
Using parallel processing and iterative algorithm methods, the calculation of the center position of sub-pixel balance and the iterative summation of perimeters is significantly reduced and the calculation accuracy and speed is improved.
It significantly reduces the amount of calculation, improves the accuracy and speed of perimeter calculation, and is suitable for different image processing scenarios, especially in high-resolution image processing, with significant time advantages.
Smart Images

Figure CN119741359A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of image processing, and in particular relates to a method for calculating the boundary perimeter of an area of interest in a high-resolution image. Background Art
[0002] In image processing, the perimeter of a region of interest (ROI) is an important topological feature. However, due to the discreteness of the image, the perimeter of the ROI cannot be directly calculated simply by the number of boundary pixels. There are two main methods for calculating the perimeter of the ROI: one is the boundary tracing method, which obtains the boundary by iterating the boundary pixels one by one, and then uses the digitized straight line segment method or the minimum polygon method to calculate the total perimeter. However, the boundary tracing method is a serial calculation, which requires high space and time costs, and the result is easily affected by the starting boundary pixels, resulting in instability of the result; the other is the sub-pixel boundary extraction method, which is based on the gray value information of the boundary area, and calculates the boundary position with sub-pixel accuracy through interpolation, curve fitting, moment method and other means, and then calculates the total perimeter. Although this method can obtain more accurate results than the boundary tracing method, its calculation process is more complicated, the amount of calculation is larger, and the fitting accuracy is affected by the fitting range. In addition, since this method relies on the gray value information of the image, the noise in the image may have an adverse effect on the calculation results.
[0003] Therefore, the existing technology faces the problems of low computational efficiency, unstable results, limited computational accuracy, noise sensitivity and limited applicability, and therefore a new technical solution is urgently needed. Summary of the invention
[0004] The purpose of the present invention is to provide a method for calculating the boundary perimeter of a region of interest in a high-resolution image. The method can be applied to different image processing scenarios. Through parallel processing and iterative algorithms, the amount of calculation is significantly reduced, and the accuracy and speed of perimeter calculation are improved.
[0005] To achieve the above object, the present invention provides a method for calculating the boundary perimeter of a region of interest in a high-resolution image, comprising the following steps:
[0006] S1, area of interest division;
[0007] Set the threshold, convert the image into a binary image, set the pixel value of the area of interest to 1, and set the pixel value of the non-interest area to 0;
[0008] S2, boundary extraction;
[0009] According to the binary image in S1, the boundary pixels are determined by using the four nearest neighbor pixels, the pixel values of the boundary pixels are set to 1, and the pixel values of the non-boundary pixels are set to 0, so as to obtain a boundary division map;
[0010] S3, calculating the sub-pixel balance center position of the boundary pixel;
[0011] Initialize the sub-pixel balance center position of the boundary pixel according to the boundary division map in S2, update the sub-pixel balance center position of the boundary pixel according to the sub-pixel balance center position of the neighboring pixel, and iterate repeatedly until convergence to obtain the sub-pixel balance center position of the boundary pixel;
[0012] S4, calculating the perimeter of boundary pixels and iteratively summing them;
[0013] The sub-pixel balance center position of the boundary pixel is obtained from S3, and the distance vector from the boundary pixel to other boundary pixels in the neighboring pixels is calculated. The distance vector is used as the perimeter value of the boundary pixel, and the perimeter value is stored in the image in the form of a grayscale value. The total perimeter of the area of interest is obtained by iterative summation.
[0014] Preferably, S3 comprises the following steps:
[0015] S301, obtaining the absolute center position of the boundary pixel;
[0016] S302, obtaining eight neighboring pixels around the boundary pixel;
[0017] S303, calculating the sub-pixel balance center position of the boundary pixel according to the grayscale values and positions of the eight neighboring pixels of the boundary pixel, and the calculation method is as follows:
[0018]
[0019] Among them, C i represents the sub-pixel balance center position of the neighboring pixel i, C represents the sub-pixel balance center position of the boundary pixel, and C 0 Indicates the absolute center position of the boundary pixel, P i Indicates whether the neighboring pixel i is a boundary pixel. If the pixel is a boundary pixel, then P i =1, if the pixel is not a boundary pixel, then P i =0;
[0020] S304, updating the sub-pixel balance center position of the boundary pixel according to the sub-pixel balance center position calculated in S303;
[0021] S305. Determine whether the difference between the iteratively updated sub-pixel balance center position and the sub-pixel balance center position of the previous iterative update is less than a preset threshold; if it is greater than the threshold, proceed to the next iteration and repeat S302 to S304; if it is less than the threshold, the iteration converges and outputs the sub-pixel balance center position of the boundary pixel.
[0022] Preferably, in S301, the initial value of the sub-pixel balance center position of the boundary pixel is the absolute center position of the boundary pixel.
[0023] Preferably, in S304, to ensure that the difference between the updated sub-pixel balance center position and the absolute center position does not exceed 1 pixel unit, a clamp function is used to perform boundary checking, and the formula is as follows:
[0024] C=clamp(C,C 0 -(1,1),C 0 +(1,1)).
[0025] Preferably, S4 comprises the following steps:
[0026] S401, obtaining the sub-pixel balance center position of the boundary pixel in S3, detecting the eight neighboring pixels of the boundary pixel in a fixed counterclockwise order, calculating the distance from the boundary pixel to the neighboring pixel, obtaining a distance vector, and using the distance vector as the perimeter value of the boundary pixel;
[0027] S402, storing the perimeter values of the boundary pixels obtained in S401 in the image in the form of grayscale values, and summing the perimeter values of the pixels;
[0028] S403, repeatedly executing S402 until the perimeter values of the pixels are accumulated into a single pixel image, and the perimeter value stored in the single pixel image is the total perimeter of the region of interest.
[0029] Preferably, in S401, the method for calculating the distance from the boundary pixel to other boundary pixels in the neighboring pixels is to set the sub-pixel balance center position of the first detected other boundary pixel as C in , the sub-pixel balance center position of the last detected other boundary pixel is C out , calculate (C out -C in ) to obtain the distance vector, and take half the length of the distance vector as the perimeter value of the boundary pixel. If the neighboring pixel contains only one other boundary pixel, the perimeter value of the boundary pixel is recorded as |CC in |.
[0030] Preferably, in S402, the perimeter values of the four pixels with coordinates (2i, 2j), (2i+1, 2j), (2i, 2j+1), and (2i+1, 2j+1) in the selected original image are summed to obtain the perimeter value of the pixel with coordinates (i, j) in the new image.
[0031] Preferably, in S402, the perimeter values of the four pixels are summed by convolution summation, and the summation result is stored as a single pixel in the new image.
[0032] Therefore, the present invention adopts the above-mentioned method for calculating the boundary perimeter of the region of interest in a high-resolution image. Compared with the existing invention, the present invention has the following significant beneficial effects:
[0033] (1) The present invention reduces the amount of calculation and improves the calculation speed through parallel processing and efficient iterative algorithms, especially having a significant time advantage when processing high-resolution images;
[0034] (2) The present invention uses sub-pixel precision to calculate the boundary position, which has good adaptability to straight lines or curves with different slopes, thereby improving the accuracy of perimeter calculation;
[0035] (3) The calculation method of the present invention is easy to implement and apply.
[0036] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 A binary image diagram of a method for calculating the boundary perimeter of an area of interest in a high-resolution image according to the present invention;
[0038] Figure 2 It is a boundary division map of a method for calculating the boundary perimeter of an area of interest in a high-resolution image of the present invention, wherein a represents checking the upper neighboring pixels, the lower neighboring pixels, the left neighboring pixels and the right neighboring pixels of the pixel; b represents a binary map of boundary pixels after marking, that is, a boundary division map;
[0039] Figure 3 This is a sub-pixel balance center position search diagram of a method for calculating the boundary perimeter of an area of interest in a high-resolution image of the present invention, wherein a represents the sub-pixel balance center position of a boundary pixel calculated according to the grayscale values and positions of its eight neighboring pixels; b represents the sub-pixel balance center position of the boundary pixel after convergence;
[0040] Figure 4The pixel perimeter and iterative summation diagram of a method for calculating the boundary perimeter of an area of interest in a high-resolution image of the present invention, wherein a represents calculating the perimeter value according to the sub-pixel balance center position of the boundary pixel and storing the perimeter value in the pixel; b represents four pixels in the original image selected when calculating the perimeter value of the pixel of the new image; c represents that after one iteration, the size of the new image is reduced compared to the original image, and the calculation result of the perimeter value is stored in the new image. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings 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. All other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Unless otherwise defined, the technical terms or scientific terms used in the present invention should be the common meaning understood by people with general skills in the field to which the present invention belongs.
[0042] Embodiment 1
[0043] like Figure 1 As shown, a method for calculating the boundary perimeter of an area of interest in a high-resolution image of the present invention comprises the following steps:
[0044] S1, area of interest division;
[0045] like Figure 1 As shown, according to the characteristics and objectives of the image, select an appropriate threshold gray value g. The selection of the threshold can be based on the histogram analysis of the image, manual setting, or the use of an adaptive threshold algorithm. Traverse each pixel in the image, and for each pixel, compare its gray value with the threshold g. If the gray value of the pixel is greater than the threshold g, the pixel is marked as a foreground pixel, that is, part of the region of interest, and its pixel value is 1; if the gray value of the pixel is less than or equal to the threshold g, the pixel is marked as a background pixel, that is, a non-region of interest, and its pixel value is 0. Based on the pixel classification results, a binary image of the region of interest is generated, in which the pixel value of the foreground pixel is 1 and the pixel value of the background pixel is 0.
[0046] The method for dividing the region of interest is well known to those skilled in the art, so it will not be described in detail here.
[0047] S2, boundary extraction;
[0048] like Figure 2As shown, create a marker image with the same size as the original image to mark the boundary pixels. The initial state of all pixels is non-boundary, and each pixel in the binary image is traversed. For a pixel, its four neighboring pixels include upper neighboring pixels, lower neighboring pixels, left neighboring pixels, and right neighboring pixels. Check the states of the upper neighboring pixels, lower neighboring pixels, left neighboring pixels, and right neighboring pixels of each pixel. If the current pixel is a foreground pixel and at least one of its four neighboring pixels is a background pixel, the pixel is marked as a boundary pixel.
[0049] Assuming the current pixel coordinates are (x, y), detect the four neighboring pixels (x-1, y), (x+1, y), (x, y-1) and (x, y+1) of the pixel (x, y). If the pixel (x, y) is a foreground pixel and at least one of its neighboring pixels is a background pixel, the pixel (x, y) in the mark image is a boundary pixel.
[0050] When marking an image, the pixel value of the detected boundary pixel is set to 1; the pixel value of the detected non-boundary pixel is set to 0. After the above operation, a binary image of the boundary pixel is obtained, that is, a boundary partition map.
[0051] S3, calculating the sub-pixel balance center position of the boundary pixel;
[0052] like Figure 3 As shown, S3 includes the following steps:
[0053] S301, according to the boundary division map in S2, initialize the sub-pixel balance center position of the boundary pixel, and set the sub-pixel balance center position of each boundary pixel to the absolute center position of the pixel. The absolute center position is usually the pixel coordinate (x, y) plus 0.5, that is, (x+0.5, y+0.5);
[0054] S302, obtaining eight neighboring pixels around the boundary pixel;
[0055] S303, for each boundary pixel, calculate the sub-pixel balance center position of the boundary pixel according to the grayscale values and positions of its eight neighboring pixels, using a weighted average method, and the calculation method is as follows:
[0056]
[0057] Among them, C i represents the sub-pixel balance center position of the neighboring pixel i, C represents the sub-pixel balance center position of the boundary pixel, and C 0 Indicates the absolute center position of the boundary pixel, P i Indicates whether the neighboring pixel i is a boundary pixel. If the pixel is a boundary pixel, then P i =1, if the pixel is not a boundary pixel, then Pi =0.
[0058] S304: Update the sub-pixel balance center position of the current pixel according to the sub-pixel balance center position calculated in S303. To ensure that the difference between the updated sub-pixel balance center position and the absolute center position does not exceed 1 pixel unit, use the clamp function to perform boundary checking, and the formula is as follows:
[0059] C=clamp(C,C 0 -(1,1),C 0 +(1,1));
[0060] S305: Determine whether the difference between the sub-pixel balance center position updated in the current iteration and the sub-pixel balance center position updated in the previous iteration is less than a preset threshold. If it is greater than the threshold, proceed to the next iteration, repeat S302 to S304 until the new sub-pixel balance center position converges. If it is less than the threshold, the iteration converges and outputs the sub-pixel balance center position of each boundary pixel.
[0061] S4, calculating the perimeter of boundary pixels and iteratively summing them;
[0062] like Figure 4 As shown, S4 includes the following steps:
[0063] S401, obtaining the sub-pixel balance center position of the boundary pixel in S3, detecting the eight neighboring pixels of the boundary pixel in a fixed counterclockwise (or clockwise) order, and detecting the sub-pixel balance center positions of other boundary pixels among the eight neighboring pixels.
[0064] If the detected neighboring pixel contains multiple other boundary pixels, the distance from the boundary pixel to the first other boundary pixel and the distance from the boundary pixel to the last other boundary pixel are calculated to obtain a distance vector, and half of the length of this distance vector is used as the perimeter value of the boundary pixel. If the neighboring pixel contains only one other boundary pixel, the perimeter value of the boundary pixel is the distance from the boundary pixel to the other boundary pixel. Let the sub-pixel balance center position of the first detected other boundary pixel be C in , the sub-pixel balance center position of the last detected other boundary pixel is C out , calculate (C out -C in ) to obtain the distance vector, and take half the length of the distance vector as the perimeter value of the current pixel. If the neighboring pixel contains only one other boundary pixel, the perimeter value of the boundary pixel is recorded as |CC in |;
[0065] S402, store the calculated perimeter value of the boundary pixel in the form of grayscale value in the image. When calculating the perimeter value of the pixel of the new image, the perimeter values of the four pixels in the original image need to be summed. The perimeter values of the four pixels with coordinates (2i, 2j), (2i+1, 2j), (2i, 2j+1), and (2i+1, 2j+1) in the selected original image are summed to obtain the perimeter value of the pixel with coordinates (i, j) in the new image.
[0066] S403, using the convolution summation method, repeatedly perform S402, each time calculate the sum of the perimeter values of the four pixels corresponding to the new (i, j) coordinates, and store the result in a new image. Since each operation will reduce the image size, the resolution of the new image will gradually decrease. When the image is reduced to a single pixel, the perimeter value stored in the pixel is the perimeter of the region of interest. By iterative summation, high-resolution images can be effectively processed and calculation accuracy can be improved.
[0067] Therefore, the present invention adopts the above-mentioned method for calculating the boundary perimeter of the area of interest in a high-resolution image. This method can be applied to different image processing scenarios. Through parallel processing and iterative algorithms, the amount of calculation is significantly reduced, and the accuracy and speed of perimeter calculation are improved.
[0068] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that they can still modify or replace the technical solution of the present invention with equivalents, and these modifications or equivalent replacements cannot cause the modified technical solution to deviate from the spirit and scope of the technical solution of the present invention.
Claims
1. A method for calculating the boundary perimeter of a region of interest in a high-resolution image, characterized in that: The following steps are involved: S1, area of interest division; Set the threshold, convert the image into a binary image, set the pixel value of the area of interest to 1, and set the pixel value of the non-interest area to 0; S2, boundary extraction; According to the binary image in S1, the boundary pixels are determined by using the four nearest neighbor pixels, the pixel values of the boundary pixels are set to 1, and the pixel values of the non-boundary pixels are set to 0, so as to obtain a boundary division map; S3, calculating the sub-pixel balance center position of the boundary pixel; Initialize the sub-pixel balance center position of the boundary pixel according to the boundary division map in S2, update the sub-pixel balance center position of the boundary pixel according to the sub-pixel balance center position of the neighboring pixel, and iterate repeatedly until convergence to obtain the sub-pixel balance center position of the boundary pixel; S4, calculating the perimeter of boundary pixels and iteratively summing them; The sub-pixel balance center position of the boundary pixel is obtained from S3, and the distance vector from the boundary pixel to other boundary pixels in the neighboring pixels is calculated. The distance vector is used as the perimeter value of the boundary pixel, and the perimeter value is stored in the image in the form of a grayscale value. The total perimeter of the area of interest is obtained by iterative summation.
2. The method for calculating the boundary perimeter of a region of interest in a high-resolution image according to claim 1, characterized in that: S3 includes the following steps: S301, obtaining the absolute center position of the boundary pixel; S302, obtaining eight neighboring pixels around the boundary pixel; S303, calculating the sub-pixel balance center position of the boundary pixel according to the grayscale values and positions of the eight neighboring pixels of the boundary pixel, and the calculation method is as follows: Among them, C i represents the sub-pixel balance center position of the neighboring pixel i, C represents the sub-pixel balance center position of the boundary pixel, and C 0 Indicates the absolute center position of the boundary pixel, P i Indicates whether the neighboring pixel i is a boundary pixel. If the pixel is a boundary pixel, then P i =1, if the pixel is not a boundary pixel, then P i =0; S304, updating the sub-pixel balance center position of the boundary pixel according to the sub-pixel balance center position calculated in S303; S305. Determine whether the difference between the iteratively updated sub-pixel balance center position and the sub-pixel balance center position of the previous iterative update is less than a preset threshold; if it is greater than the threshold, proceed to the next iteration and repeat S302 to S304; if it is less than the threshold, the iteration converges and outputs the sub-pixel balance center position of the boundary pixel.
3. The method for calculating the boundary perimeter of a region of interest in a high-resolution image according to claim 2, characterized in that: In S301 , the initial value of the sub-pixel balance center position of the boundary pixel is the absolute center position of the boundary pixel.
4. The method for calculating the boundary perimeter of a region of interest in a high-resolution image according to claim 2, characterized in that: In S304, to ensure that the difference between the updated sub-pixel balance center position and the absolute center position does not exceed 1 pixel unit, a clamp function is used to perform boundary checking, and the formula is as follows: C=clamp(C,C 0 -(1,1),C 0 +(1,1))。 5. The method for calculating the boundary perimeter of a region of interest in a high-resolution image according to claim 1, characterized in that: S4 includes the following steps: S401, obtaining the sub-pixel balance center position of the boundary pixel in S3, detecting the eight neighboring pixels of the boundary pixel in a fixed counterclockwise order, calculating the distance from the boundary pixel to other boundary pixels in the neighboring pixels, obtaining a distance vector, and using the distance vector as the perimeter value of the boundary pixel; S402, storing the perimeter values of the boundary pixels obtained in S401 in the image in the form of grayscale values, and summing the perimeter values of the pixels; S403, repeatedly executing S402 until the perimeter values of the pixels are accumulated into a single pixel image, and the perimeter value stored in the single pixel image is the total perimeter of the region of interest.
6. The method for calculating the boundary perimeter of a region of interest in a high-resolution image according to claim 5, characterized in that: In S401, the method for calculating the distance between the boundary pixel and other boundary pixels in the neighboring pixels is to set the sub-pixel balance center position of the first detected other boundary pixel as C in , the sub-pixel balance center position of the last detected other boundary pixel is C out , calculate (C out -C in ) to obtain the distance vector, and take half the length of the distance vector as the perimeter value of the boundary pixel. If the neighboring pixel contains only one other boundary pixel, the perimeter value of the boundary pixel is recorded as |cC in |.
7. The method for calculating the boundary perimeter of a region of interest in a high-resolution image according to claim 5, characterized in that: In S402, the perimeter values of the four pixels with coordinates (2i, 2j), (2i+1, 2j), (2i, 2j+1), and (2i+1, 2j+1) in the selected original image are summed to obtain the perimeter value of the pixel with coordinates (i, j) in the new image.
8. The method for calculating the boundary perimeter of a region of interest in a high-resolution image according to claim 7, characterized in that: In S402, the perimeter values of the four pixels are summed by using a convolution summation method, and the summation result is stored as a single pixel in the new image.
Citation Information
Patent Citations
Special boundary measuring system and method
CN103292725A
Grayscale target perimeter estimation method based on image particle and sub-pixel boundary detection
CN107909610A
Line structured light center extraction method and system based on space gray gravity center propulsion
CN116681753A
Measurement method and device, electronic equipment and computer readable storage medium
CN117689621A
Image processing apparatus, image processing method, and program
JP2005136975A
Cited By
Method for quickly estimating sub-voxel precision of surface area of region of interest in voxel model
CN120852506A