Image edge extraction method and device
By extracting edge features and adjusting gradient direction from X-ray images, combined with preset threshold processing, the problem of low accuracy in edge extraction of X-ray images is solved, and clearer edge images are generated.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU SANTAN MEDICAL TECH
- Filing Date
- 2022-07-29
- Publication Date
- 2026-07-03
Smart Images

Figure CN115294166B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to an image edge extraction method and apparatus. Background Technology
[0002] In the medical field, X-ray images are a common type of medical imaging. Edge extraction from X-ray images yields X-ray contour images, which physicians can use to analyze a patient's condition. For example, physicians can analyze lesions by directly observing the X-ray contour image of the affected area; alternatively, electronic devices can register a patient's X-ray contour image with a CT image to obtain a simulated X-ray image of a specific area, which physicians can then analyze to determine the condition of that specific area.
[0003] It is evident that X-ray contour images are of great significance in assisting physicians in analyzing patients' conditions.
[0004] However, due to the characteristics of X-ray images such as complex image content, high data noise, and low signal-to-noise ratio, the edge extraction of X-ray images in the existing technology is easily interfered with, resulting in low accuracy and poor quality of the obtained X-ray contour images. Summary of the Invention
[0005] The purpose of this invention is to provide an image edge extraction method and apparatus to improve the accuracy of the obtained edge image. The specific technical solution is as follows:
[0006] In a first aspect, embodiments of the present invention provide an image edge extraction method, the method comprising:
[0007] Acquire X-ray images;
[0008] Edge features are extracted from the X-ray image to obtain an initial edge image;
[0009] For each pixel in the initial edge image, the gradient direction corresponding to the pixel is obtained based on the pixel value of the pixel and the pixel values of the pixels in the first preset neighborhood of the pixel. The pixel value of the pixel is adjusted according to the obtained gradient direction to obtain the intermediate edge image.
[0010] Based on a preset first edge strength threshold and a second edge strength threshold, the pixel values of each pixel in the intermediate edge image are adjusted to obtain the edge image of the X-ray image.
[0011] In one embodiment of the present invention, adjusting the pixel values of each pixel in the intermediate edge image based on a preset first edge strength threshold and a second edge strength threshold to obtain the edge image of the X-ray image includes:
[0012] For each pixel in the intermediate edge image, the pixel value of that pixel is adjusted in the following way to obtain the edge image of the X-ray image:
[0013] If the pixel value of the pixel is greater than the preset first edge strength threshold, then the pixel value of the pixel is incremented by the first preset value;
[0014] If the pixel value of the pixel is less than the preset second edge strength threshold, then the pixel value of the pixel is subtracted from the second preset value, wherein the first edge strength threshold is greater than the second edge strength threshold.
[0015] In one embodiment of the present invention, the step of extracting edge features from the X-ray image to obtain an initial edge image includes:
[0016] Based on the pixel values of each pixel in the X-ray image and the pixel values of the pixels in the first preset neighborhood of each pixel, the first gradient value corresponding to each pixel in the horizontal direction and the second gradient value corresponding to each pixel in the vertical direction are obtained.
[0017] Based on the first gradient value and the second gradient value corresponding to each pixel in the X-ray image, the edge intensity corresponding to each pixel is obtained, and an initial edge image is generated based on the obtained edge intensity.
[0018] In one embodiment of the present invention, obtaining the gradient direction corresponding to the pixel determined based on the pixel value of the pixel and the pixel values of pixels in a first preset neighborhood of the pixel, and adjusting the pixel value of the pixel according to the obtained gradient direction, includes:
[0019] The gradient direction corresponding to the pixel is obtained based on the first gradient value and the second gradient value corresponding to the pixel.
[0020] From the preset angle partitions, determine the target angle partition to which the obtained gradient direction belongs, wherein each angle partition includes two sub-angle partitions that are centrally symmetrical;
[0021] From the second preset neighborhood of the pixel in each sub-angle partition included in the target angle partition, the reference pixel corresponding to the pixel is determined respectively.
[0022] Adjust the pixel value of the reference pixel based on the pixel value of the reference pixel.
[0023] In one embodiment of the present invention, adjusting the pixel value of a pixel based on the determined pixel value of a reference pixel includes:
[0024] Based on the first gradient value and the second gradient value corresponding to the pixel, determine the interpolation ratio corresponding to each reference pixel in each sub-angle partition of the target angle partition;
[0025] For each sub-angle partition of the target angle partition, pixel interpolation is calculated based on the pixel value of each reference pixel and the corresponding interpolation ratio;
[0026] If the pixel interpolation value corresponding to each sub-angle partition of the target angle partition is greater than the pixel value of that pixel, then the pixel value of that pixel is adjusted to 0.
[0027] In one embodiment of the present invention, after adjusting the pixel values of each pixel in the intermediate edge image based on a preset first edge strength threshold and a second edge strength threshold to obtain the edge image of the X-ray image, the method further includes:
[0028] Adjust the pixel values of each pixel in the edge image of the X-ray image as follows:
[0029] Adjust pixel values that are greater than the preset third edge strength threshold to the pixel values corresponding to the edge pixels;
[0030] Pixel values that are less than a preset fourth edge strength threshold are adjusted to the pixel values corresponding to non-edge pixels, wherein the third edge strength threshold is greater than the fourth edge strength threshold;
[0031] For a pixel value that is not greater than the third edge strength threshold and not less than the fourth edge strength threshold, if there is a determined edge pixel in the third preset neighborhood of the pixel corresponding to the pixel value, then the pixel value is adjusted to the pixel value corresponding to the edge pixel.
[0032] Secondly, embodiments of the present invention provide an image edge extraction device, the device comprising:
[0033] The image acquisition module is used to acquire X-ray images;
[0034] An edge feature extraction module is used to extract edge features from the X-ray image to obtain an initial edge image;
[0035] The first pixel value adjustment module is used to obtain the gradient direction corresponding to each pixel in the initial edge image, which is determined by the pixel value of the pixel and the pixel values of the pixels in the first preset neighborhood of the pixel, and adjust the pixel value of the pixel according to the obtained gradient direction to obtain the intermediate edge image.
[0036] The second pixel value adjustment module is used to adjust the pixel value of each pixel in the intermediate edge image based on a preset first edge strength threshold and a second edge strength threshold, so as to obtain the edge image of the X-ray image.
[0037] In one embodiment of the present invention, the second pixel value adjustment module is specifically used to adjust the pixel value of each pixel in the intermediate edge image in the following manner to obtain the edge image of the X-ray image:
[0038] If the pixel value of the pixel is greater than a preset first edge strength threshold, then the pixel value of the pixel is increased by a first preset value; if the pixel value of the pixel is less than a preset second edge strength threshold, then the pixel value of the pixel is decreased by a second preset value, wherein the first edge strength threshold is greater than the second edge strength threshold.
[0039] In one embodiment of the present invention, the edge feature extraction module includes:
[0040] The gradient value acquisition submodule is used to obtain the first gradient value of each pixel in the horizontal direction and the second gradient value in the vertical direction based on the pixel value of each pixel in the X-ray image and the pixel value of each pixel in the first preset neighborhood of each pixel.
[0041] The edge intensity acquisition submodule is used to obtain the edge intensity corresponding to each pixel point according to the first gradient value and the second gradient value corresponding to each pixel point in the X-ray image, and to obtain an initial edge image generated based on the obtained edge intensity.
[0042] In one embodiment of the present invention, the first pixel value adjustment module includes:
[0043] The gradient direction acquisition submodule is used to obtain the gradient direction corresponding to each pixel in the initial edge image based on the first gradient value and the second gradient value corresponding to the pixel.
[0044] The target angle partition determination submodule is used to determine the target angle partition to which the obtained gradient direction belongs from the preset angle partitions, wherein each angle partition includes two sub-angle partitions that are centrally symmetrical.
[0045] The reference pixel point determination submodule determines the reference pixel point corresponding to the pixel point from the second preset neighborhood of the pixel point in each sub-angle partition included in the target angle partition;
[0046] The pixel value adjustment submodule is used to adjust the pixel value of a given reference pixel to obtain the intermediate edge image.
[0047] In one embodiment of the present invention, the pixel value adjustment submodule is specifically used to determine the interpolation ratio corresponding to each reference pixel in each sub-angle partition of the target angle partition according to the first gradient value and the second gradient value corresponding to the pixel; for each sub-angle partition of the target angle partition, the pixel interpolation is calculated based on the pixel value of each reference pixel and the corresponding interpolation ratio; if the pixel interpolation corresponding to each sub-angle partition of the target angle partition is greater than the pixel value of the pixel, the pixel value of the pixel is adjusted to 0; and the intermediate edge image is obtained based on the adjustment result.
[0048] In one embodiment of the present invention, the apparatus further includes:
[0049] The third pixel value adjustment module is used to adjust the pixel values of each pixel in the edge image of the X-ray image after the second pixel value adjustment module has adjusted the pixel values, in the following manner:
[0050] Adjust pixel values that are greater than the preset third edge strength threshold to the pixel values corresponding to the edge pixels;
[0051] Pixel values that are less than a preset fourth edge strength threshold are adjusted to the pixel values corresponding to non-edge pixels, wherein the third edge strength threshold is greater than the fourth edge strength threshold;
[0052] For a pixel value that is not greater than the third edge strength threshold and not less than the fourth edge strength threshold, if there is a determined edge pixel in the third preset neighborhood of the pixel corresponding to the pixel value, then the pixel value is adjusted to the pixel value corresponding to the edge pixel.
[0053] Thirdly, embodiments of the present invention provide an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0054] Memory, used to store computer programs;
[0055] When a processor executes a program stored in memory, it implements the steps of the method described in the first aspect above.
[0056] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the method described in the first aspect above.
[0057] Fifthly, embodiments of the present invention also provide a computer program product containing instructions that, when run on a computer, cause the computer to perform the method steps described in the first aspect.
[0058] As can be seen from the above, when performing edge extraction on X-ray images using the image edge extraction scheme provided in this embodiment of the invention, the X-ray image is first subjected to edge feature extraction to obtain an initial edge image. For each pixel in the initial edge image, the gradient direction corresponding to each pixel is obtained based on the pixel value of each pixel in the initial edge image and the pixel value of each pixel in the first preset neighborhood. Since the gradient direction represents the direction in which the pixel value of each pixel changes at the largest rate in the first preset neighborhood, adjusting the pixel value of each pixel according to the obtained gradient direction is beneficial to eliminating redundant pixels with non-maximum pixel values in the first preset neighborhood, retaining pixels with larger pixel values in the gradient direction, reducing interference information in the initial edge image, and obtaining an intermediate edge image with clearer edge contours.
[0059] Then, based on the preset first edge strength threshold and second edge strength threshold, the pixel values of each pixel in the intermediate edge image are adjusted again. This increases or decreases the pixel values of each pixel, making the distinction between light and dark in the intermediate edge image more obvious, further reducing the interference information in the intermediate edge image, making the edge contour in the adjusted edge image clearer, and improving the accuracy of the edge image of the obtained X-ray image.
[0060] Of course, implementing any product or method of the present invention does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0061] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0062] Figure 1 A schematic flowchart of the first image edge extraction method provided in an embodiment of the present invention;
[0063] Figure 2 A schematic flowchart of the second image edge extraction method provided in an embodiment of the present invention;
[0064] Figure 3 A schematic flowchart of the third image edge extraction method provided in this embodiment of the invention;
[0065] Figure 4 A schematic flowchart of the fourth image edge extraction method provided in this embodiment of the invention;
[0066] Figure 5 An X-ray image of the human spine region;
[0067] Figure 6 The edge image is obtained by applying existing image edge extraction methods;
[0068] Figure 7 The edge image is obtained by applying the image edge extraction method provided in the embodiments of the present invention;
[0069] Figure 8 This is a schematic diagram of the structure of the first image edge extraction device provided in an embodiment of the present invention;
[0070] Figure 9 This is a schematic diagram of the structure of the second image edge extraction device provided in an embodiment of the present invention;
[0071] Figure 10 This is a schematic diagram of the structure of the third image edge extraction device provided in an embodiment of the present invention;
[0072] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0073] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of the present invention.
[0074] First, the subject responsible for implementing the solution provided in the embodiments of the present invention will be described.
[0075] The entity executing the solution provided in this embodiment of the invention can be any electronic device with data processing capabilities.
[0076] The image edge extraction method provided in the embodiments of the present invention will be described in detail below.
[0077] See Figure 1 , Figure 1 This is a flowchart illustrating the first image edge extraction method provided in an embodiment of the present invention. The method includes the following steps S101-S104.
[0078] Step S101: Acquire X-ray images.
[0079] X-ray images can be acquired by any X-ray image acquisition device. For example, the aforementioned X-ray image acquisition device can be a large X-ray machine, or a C-arm X-ray machine, a G-arm X-ray machine, etc.
[0080] Step S102: Extract edge features from the X-ray image to obtain an initial edge image.
[0081] Specifically, the initial edge image can be obtained in the following way.
[0082] In one implementation, edge features can be extracted from the X-ray image based on an edge extraction operator to obtain an initial edge image. For example, the edge extraction operator can be the Roberts operator, Prewitt operator, Robinson operator, LOG (Laplacian of Gaussian) operator, etc.
[0083] In another implementation, based on the pixel values of pixels in the X-ray image, a first gradient value in the horizontal direction and a second gradient value in the vertical direction corresponding to each pixel can be obtained. Then, based on the first and second gradient values, the edge intensity corresponding to each pixel can be obtained, resulting in an initial edge image generated based on the obtained edge intensities. Detailed implementation methods will be provided later. Figure 2 Steps S202 and S203 in the illustrated embodiment will not be described in detail here.
[0084] Step S103: For each pixel in the initial edge image, obtain the gradient direction corresponding to the pixel based on the pixel value of the pixel and the pixel values of the pixels in the first preset neighborhood of the pixel. Adjust the pixel value of the pixel according to the obtained gradient direction to obtain the intermediate edge image.
[0085] The embodiments of the present invention do not limit the size of the first preset neighborhood, which can be set by the staff based on experience. For example, the size of the first preset neighborhood can be 3×3, or 4×4, etc.
[0086] For each pixel in the initial edge image, the gradient direction corresponding to that pixel is the direction in which the pixel value has the highest rate of change within its first preset neighborhood, and the gradient direction is an angle value.
[0087] Specifically, the gradient direction of a pixel can be obtained based on its first and second gradient values. Details of the implementation method will be provided later. Figure 3 Step S304 in the illustrated embodiment will not be described in detail here.
[0088] Specifically, after obtaining the gradient direction corresponding to each pixel in the initial edge image, the pixel value of each pixel can be adjusted according to the obtained gradient direction in the following way to obtain the intermediate edge image.
[0089] In one implementation, target pixels can be determined within a first preset neighborhood of the pixel, located on the gradient direction corresponding to the pixel and in the opposite direction to the gradient direction corresponding to the pixel. The pixel value of the pixel is then adjusted based on the pixel value of the target pixel. Specifically, it can be determined whether the pixel value of the current pixel is greater than the pixel value of the target pixel; if not, the pixel value of the current pixel is set to 0.
[0090] The following example illustrates how to determine the target pixel located in the gradient direction corresponding to the pixel.
[0091] For example, if the size of the first preset neighborhood is 3×3, and the gradient direction corresponding to pixel A is 90°, then the target pixel located in the 90° direction of pixel A can be determined as: pixel B located directly above pixel A; the target pixel located in the opposite direction of the gradient direction of pixel A is: and pixel C located directly below pixel A.
[0092] Since the gradient direction represents the direction in which the pixel value of a pixel has the highest rate of change within its first preset neighborhood, determining the target pixel based on the gradient direction and adjusting the pixel value of the target pixel according to its pixel value helps to eliminate pixels with non-maximum pixel values within the first preset neighborhood, reducing redundant pixels in the initial image and making the edge contours in the initial image clearer.
[0093] In some cases, within the first preset neighborhood of a pixel, there may be no target pixels located in the gradient direction corresponding to that pixel or in the opposite direction to the gradient direction corresponding to that pixel.
[0094] For example, when the size of the first preset neighborhood is 3×3, if the gradient direction corresponding to pixel D is 30°, there is no target pixel in the first preset neighborhood of pixel D located in the gradient direction corresponding to pixel D and in the opposite direction of the gradient direction corresponding to pixel D.
[0095] In the above situation, the following implementation method can be used to adjust the pixel value of the pixel according to the gradient direction corresponding to the pixel.
[0096] In another implementation, the target angle partition to which the obtained gradient direction belongs can be determined from a preset angle partition. Then, a reference pixel corresponding to the pixel can be determined from the second preset neighborhood of the pixel in each sub-angle partition included in the target angle partition. Based on the pixel value of the determined reference pixel, the pixel value is adjusted. Detailed implementation methods will be provided later. Figure 3 Steps S305-S307 in the illustrated embodiment will not be described in detail here.
[0097] Step S104: Based on the preset first edge intensity threshold and second edge intensity threshold, adjust the pixel values of each pixel in the intermediate edge image to obtain the edge image of the X-ray image.
[0098] In this step, the pixel values of each pixel in the intermediate edge image are adjusted based on the first edge strength threshold and the second edge strength threshold, which can make the edge contour in the intermediate edge image clearer.
[0099] Specifically, the pixel values of each pixel in the intermediate edge image can be adjusted in the following way to obtain the edge image of the X-ray image.
[0100] In one implementation, for each pixel in the middle edge image, the pixel value can be adjusted in the following way:
[0101] If the pixel value of a pixel is greater than a preset first edge strength threshold, then the pixel value of the pixel is increased by a first preset value; if the pixel value of a pixel is less than a preset second edge strength threshold, then the pixel value of the pixel is decreased by a second preset value. The first edge strength threshold is greater than the second edge strength threshold.
[0102] The first and second preset values mentioned above can be set by staff based on experience.
[0103] If the pixel value of a pixel is less than 0 after subtracting the second preset value from the pixel value of that pixel, then the pixel value of that pixel can be determined as 0.
[0104] This increases the pixel values of pixels with values greater than the first edge strength threshold, making these pixels brighter and clearer in the middle edge image; simultaneously, it decreases the pixel values of pixels with values less than the second edge strength threshold, making these pixels darker and blurrier in the middle edge image. It can be seen that this improves the distinction between light and dark areas of each pixel when displayed in the middle edge image, making the edge contours in the middle edge image clearer.
[0105] It should be noted that the embodiments of the present invention do not limit the specific values of the first edge intensity threshold and the second edge intensity threshold. The first edge intensity threshold and the second edge intensity threshold can be determined by the staff based on the characteristics of the X-ray image through preset experiments or other methods.
[0106] For X-ray images, the pixel value differences between individual pixels are inherently small. Therefore, in the intermediate edge image obtained from the X-ray image, the pixel value differences between individual pixels are also small. Consequently, the difference between the first edge intensity used to enhance pixels and the second edge intensity used to suppress pixels should not be too large. In one scenario, the first edge intensity threshold can be 35, and the second edge intensity threshold can be 20.
[0107] In X-ray images, edge pixels have higher pixel values, while non-edge pixels have lower pixel values. Therefore, for each pixel in the intermediate edge image, a first preset value is added to the pixel values of pixels with values greater than a first threshold, making these pixels brighter and clearer in the intermediate edge image, thus improving the clear display of edge pixels. Conversely, a second preset value is subtracted from the pixel values of pixels with values less than the first threshold, making these pixels darker and blurrier in the intermediate edge image, thus suppressing or eliminating non-edge pixels. This improves the contrast between light and dark areas of edge and non-edge pixels in the intermediate edge image, resulting in clearer edge contours in the final edge image and enhancing the accuracy of the edge image in the obtained X-ray image.
[0108] Other implementation methods are detailed in subsequent embodiments and will not be described in detail here.
[0109] As can be seen from the above, when using the image edge extraction method provided in this embodiment of the invention to extract edges from X-ray images, the edge features of the X-ray image are first extracted to obtain an initial edge image. For each pixel in the initial edge image, the gradient direction corresponding to each pixel is obtained based on the pixel value of each pixel in the initial edge image and the pixel value of each pixel in the first preset neighborhood. Since the gradient direction represents the direction in which the pixel value of each pixel changes at the largest rate in the first preset neighborhood, adjusting the pixel value of each pixel according to the obtained gradient direction is beneficial to eliminating redundant pixels with non-maximum pixel values in the first preset neighborhood, retaining pixels with larger pixel values in the gradient direction, reducing interference information in the initial edge image, and obtaining an intermediate edge image with clearer edge contours.
[0110] Then, based on the preset first edge strength threshold and second edge strength threshold, the pixel values of each pixel in the intermediate edge image are adjusted again. This increases or decreases the pixel values of each pixel, making the distinction between light and dark in the intermediate edge image more obvious, further reducing the interference information in the intermediate edge image, making the edge contour in the adjusted edge image clearer, and improving the accuracy of the edge image of the obtained X-ray image.
[0111] The following describes other implementation methods for adjusting the pixel values of each pixel in the intermediate edge image based on the preset first edge strength threshold and second edge strength threshold in the aforementioned step S104.
[0112] In another implementation, if the pixel value of the pixel is greater than a preset first edge strength threshold, then the pixel value of the pixel is incremented by a first preset value; if the pixel value of the pixel is less than a preset second edge strength threshold, then the pixel value of the pixel is set to 0.
[0113] This enhances pixels with values greater than the first edge strength threshold, making them brighter and clearer in the middle edge image. At the same time, it sets the pixel values of pixels with values less than the preset second edge strength threshold to 0, so that these pixels cannot be displayed in the middle edge image. In other words, pixels with values less than the preset second edge strength threshold are removed from the middle edge image.
[0114] Since pixels with values less than the preset second edge intensity threshold are often not edge pixels in X-ray images, removing these pixels helps reduce their interference in edge images.
[0115] In one embodiment of the present invention, before the aforementioned step S102, the obtained X-ray image may be preprocessed so that the subsequent step S102 can extract edge features from the X-ray image to obtain an initial edge image.
[0116] In one scenario, the preprocessing described above can be Gaussian filtering. This helps to filter out noise that might interfere with edge extraction while preserving the main information of the X-ray image.
[0117] exist Figure 1 Based on the illustrated embodiment, when extracting edge features from an X-ray image to obtain an initial edge image, a first gradient value in the horizontal direction and a second gradient value in the vertical direction can be obtained based on the pixel values of each pixel in the X-ray image and the pixel values of pixels within a first preset neighborhood of each pixel. Then, the edge intensity corresponding to each pixel is obtained based on the first and second gradient values, resulting in an initial edge image generated based on the obtained edge intensity. In view of the above, this embodiment of the invention provides a second image edge extraction method.
[0118] See Figure 2 , Figure 2 This is a flowchart illustrating a second image edge extraction method provided in an embodiment of the present invention. The method includes the following steps S201-S205.
[0119] Step S201: Acquire X-ray images.
[0120] The above step S201 is the same as the aforementioned Figure 1 Step S101 is the same in the illustrated embodiment, and will not be repeated here.
[0121] Step S202: Based on the pixel values of each pixel in the X-ray image and the pixel values of the pixels in the first preset neighborhood of each pixel, obtain the first gradient value in the horizontal direction and the second gradient value in the vertical direction for each pixel.
[0122] The first gradient value represents the rate of change of the pixel value of a pixel in the horizontal direction within its first preset neighborhood, and can measure the degree of difference between the pixel value of the pixel and the pixel values of the pixels in the horizontal direction within its first preset neighborhood; the second gradient value represents the rate of change of the pixel value of a pixel in the vertical direction within its first preset neighborhood, and can measure the degree of difference between the pixel value of the pixel and the pixel values of the pixels in the vertical direction within its first preset neighborhood.
[0123] Specifically, for each pixel in an X-ray image, a horizontal convolution kernel can be used to perform convolution calculations centered on the pixel within its neighborhood, yielding the first gradient value corresponding to that pixel in the horizontal direction. Similarly, a vertical convolution kernel can be used to perform convolution calculations centered on the pixel within its neighborhood, yielding the second gradient value corresponding to that pixel in the vertical direction.
[0124] The size of the convolution kernel is the same as that of the first preset neighborhood. For example, if the size of the first preset neighborhood is 3×3, then the size of the convolution kernel is also 3×3.
[0125] In one case, the convolution kernel applied in the horizontal direction can be a Sobelx convolution kernel, and the convolution kernel applied in the vertical direction can be a Sobely convolution kernel.
[0126] Step S203: Based on the first gradient value and the second gradient value corresponding to each pixel in the X-ray image, obtain the edge intensity corresponding to each pixel, and obtain the initial edge image generated based on the obtained edge intensity.
[0127] In this step, the edge intensity corresponding to a pixel can characterize the degree of difference between the pixel value of that pixel and the pixel values of other pixels in its first preset neighborhood.
[0128] It is understandable that the greater the edge intensity of a pixel, the greater the difference between the pixel value of that pixel and the pixel values of other pixels in its first preset neighborhood. In other words, the greater the probability that the pixel is an edge pixel in the X-ray image.
[0129] Specifically, the edge intensity corresponding to each pixel can be obtained in the following ways.
[0130] In one implementation, the sum of the squares of the first gradient value and the second gradient value corresponding to each pixel can be calculated, and the square root of the sum of squares can be calculated. The result is used as the edge intensity corresponding to each pixel. This can be expressed by the following formula:
[0131]
[0132] Where MAG represents the edge intensity corresponding to the pixel, d x d represents the first gradient value corresponding to the pixel. y This represents the second gradient value corresponding to the pixel.
[0133] In another implementation, the sum of the absolute values of the first and second gradient values corresponding to each pixel can be calculated, and the result can be used as the edge intensity corresponding to each pixel. This can be expressed by the following formula:
[0134] MAG = |d x |+|d y |
[0135] Step S204: For each pixel in the initial edge image, obtain the gradient direction corresponding to the pixel based on the pixel value of the pixel and the pixel values of the pixels in the first preset neighborhood of the pixel. Adjust the pixel value of the pixel according to the obtained gradient direction to obtain the intermediate edge image.
[0136] Step S205: Based on the preset first edge strength threshold and second edge strength threshold, adjust the pixel values of each pixel in the intermediate edge image to obtain the edge image of the X-ray image.
[0137] The aforementioned steps S204-S205 Figure 1 In the illustrated embodiment, steps S103-S104 are the same and will not be repeated here.
[0138] Since the first gradient value represents the rate of change of the pixel value in the horizontal direction within its first preset neighborhood, and the second gradient value represents the rate of change of the pixel value in the vertical direction within its first preset neighborhood, and the edge strength can be measured by the rate of change of the pixel value, calculating the gradients in both the horizontal and vertical directions and obtaining the edge strength of the pixel based on the gradients in these two directions can more accurately measure the difference between the pixel value of the pixel and the pixel values of the pixels in its first preset neighborhood, thus improving the accuracy of the obtained edge strength.
[0139] exist Figure 2Based on the illustrated embodiment, when adjusting the pixel values of pixels in the initial edge image, the gradient direction corresponding to the pixel can be obtained according to the first gradient value and the second gradient value corresponding to the pixel. A reference pixel corresponding to the pixel is then determined within a second preset neighborhood of the pixel based on the gradient direction. Furthermore, the pixel value of the pixel is adjusted based on the determined pixel value of the reference pixel. In view of the above, this embodiment of the invention provides a third image edge extraction method.
[0140] See Figure 3 , Figure 3 This is a flowchart illustrating the third image edge extraction method provided in an embodiment of the present invention. The method includes the following steps S301-S308.
[0141] Step S301: Acquire X-ray image.
[0142] Step S302: Based on the pixel values of each pixel in the X-ray image and the pixel values of the pixels in the first preset neighborhood of each pixel, obtain the first gradient value in the horizontal direction and the second gradient value in the vertical direction for each pixel.
[0143] Step S303: Based on the first gradient value and the second gradient value corresponding to each pixel in the X-ray image, obtain the edge intensity corresponding to each pixel, and obtain the initial edge image generated based on the obtained edge intensity.
[0144] Steps S301-S303 above are the same as those mentioned above. Figure 2 In the illustrated embodiment, steps S201-S203 are the same and will not be repeated here.
[0145] Step S304: For each pixel in the initial edge image, obtain the gradient direction corresponding to the pixel based on the first gradient value and the second gradient value corresponding to the pixel.
[0146] As can be seen from the foregoing embodiments, for each pixel in the initial edge image, the gradient direction corresponding to the pixel is: the direction in which the pixel value of the pixel has the highest rate of change in its first preset neighborhood, and the gradient direction is an angle value.
[0147] In one implementation, the gradient direction corresponding to a pixel can be calculated using the following formula:
[0148] angel = arctan2(d y d x )
[0149] Here, angel represents the gradient direction corresponding to the pixel.
[0150] Therefore, for any pixel (r, c), the gradient direction corresponding to that pixel can be calculated using the following formula:
[0151] angel(r, c) = arctan2{d y (r, c), d x (r, c)}
[0152] Where (r, c) represents the image position of the pixel, angel(r, c) represents the gradient direction corresponding to the pixel located at (r, c), and d x (r, c) represents the first gradient value corresponding to the pixel located at (r, c), d y (r, c) represents the second gradient value corresponding to the pixel located at (r, c).
[0153] Step S305: Determine the target angle partition to which the obtained gradient direction belongs from the preset angle partitions.
[0154] Each angular partition comprises two centrally symmetrical sub-angular partitions. The vertices of the two sub-angular partitions within each angular partition coincide, and they are centrally symmetrical about the vertices.
[0155] In one embodiment, the aforementioned preset angle partitioning can be as follows:
[0156] First angular division: (45°, 90°] ∪ (-135°, -90°];
[0157] Second angular partition: (90°, 135°] ∪ (-90°, -45°];
[0158] Third angle partition: [0°, 45°] ∪ [-180°, -135°];
[0159] Fourth angle division: (135°, 180°] ∪ (-45°, 0°).
[0160] Each angular partition contains two sets, which are the two sub-angular partitions corresponding to that angular partition.
[0161] Of course, the above-mentioned angle partitioning method is only an example, and the embodiments of the present invention do not limit the above-mentioned angle partitioning method or the number of angle partitions.
[0162] The following example illustrates how to determine the target angle partitioning based on the gradient direction.
[0163] For example, if the gradient direction corresponding to pixel E is 60°, and 60° belongs to the first angle partition mentioned above, then the target angle partition is the first angle partition mentioned above; as another example, if the gradient direction corresponding to pixel F is 30°, and 30° belongs to the third angle partition mentioned above, then the target angle partition is the third angle partition mentioned above.
[0164] Step S306: Determine the reference pixel corresponding to the pixel in the second preset neighborhood of the pixel in each sub-angle partition included in the target angle partition.
[0165] The size of the second preset neighborhood can be set by staff based on experience. The size of the second preset neighborhood can be the same as or different from the size of the first preset neighborhood.
[0166] Specifically, for each sub-angle partition included in the target angle partition, a pixel located in the sub-angle partition and within the second preset neighborhood of the pixel can be determined as a reference pixel.
[0167] For example, if the second preset neighborhood size is 3×3, the gradient direction corresponding to pixel point E(r, c) is 60°, the target angle partition is the first angle partition mentioned above, the target angle partition includes sub-angle partition a1: (45°, 90°], and sub-angle partition a2 (-135°, -90°], then the pixel points located in a1 and within the 3×3 neighborhood of E are: pixel point F (r-1, c-1) to the upper left of pixel point E and pixel point G (r-1, c) above pixel point E. That is, pixel point F and pixel point G are the reference pixel points corresponding to a1.
[0168] Similarly, within the 3×3 neighborhood of the pixel in sub-angle partition a2, the pixel H(r+1, c+1) to the lower right of pixel E and the pixel I(r+1, c) above pixel E can be determined as the reference pixel of a2.
[0169] It should be noted that the above examples are for ease of understanding only, and the number of reference pixels determined varies depending on the size of the second preset neighborhood.
[0170] Step S307: Based on the pixel value of the determined reference pixel, adjust the pixel value of the reference pixel to obtain the middle edge image.
[0171] In one implementation, the pixel value of the pixel can be adjusted through the following steps A-C.
[0172] Step A: Based on the first gradient value and the second gradient value corresponding to the pixel, determine the interpolation ratio corresponding to each reference pixel in each sub-angle partition of the target angle partition.
[0173] The number of the aforementioned difference ratios is equal to the number of reference pixels in each sub-angle partition.
[0174] In one scenario, for a pixel (r, c), if each sub-angle partition corresponding to this pixel contains two reference pixels, then the interpolation ratios corresponding to these two reference pixels can be: |d x (r, c)| / |d y (r, c)| and (1-|d x (r, c)| / |d y (r, c)|).
[0175] Step B: For each sub-angle partition of the target angle partition, calculate the pixel interpolation based on the pixel value of each reference pixel and the corresponding interpolation ratio.
[0176] Specifically, for each sub-angle partition of the target angle partition, the product of each reference pixel point located in the sub-angle partition and the above interpolation ratio can be calculated, and the calculation result can be used as the pixel interpolation corresponding to the sub-angle partition.
[0177] For example, for pixel point E, its corresponding sub-angle partitions a1 and a2, the pixel values of the two reference pixels in sub-angle partition a1 are S1 and S2, and the pixel values of the two reference pixels in sub-angle partition a2 are S3 and S4. The interpolation ratios of each reference pixel in angle partitions a1 and a2 are P1 and (1-P1), respectively. Then the pixel interpolation corresponding to a1 is: S1*P1+S2*(1-P1), and the pixel interpolation corresponding to a2 is: S3*P1+S4*(1-P1).
[0178] Step C: If the pixel interpolation value corresponding to each sub-angle partition of the target angle partition is greater than the pixel value of that pixel, then adjust the pixel value of that pixel to 0.
[0179] The processing steps A-C above can be called non-maximum suppression processing, and the intermediate edge image obtained after processing steps A-C can be called the nonMaxsup (non-maximum suppression) matrix.
[0180] Since the gradient interpolation corresponding to a pixel represents the possible maximum value in the gradient direction within the second preset neighborhood of that pixel, if the pixel value is less than any pixel interpolation value, it means that the pixel value is not a maximum value within its second preset neighborhood. Adjusting the pixel value to 0 helps to eliminate pixels with non-maximum values within the first preset neighborhood, reducing redundant pixels in the initial edge image. Therefore, by performing non-maximum suppression processing on the pixels in the initial edge image, interference information in the initial edge image is reduced, resulting in clearer edge contours in the obtained intermediate edge image.
[0181] In another implementation, it can be directly determined whether the pixel value of the pixel is greater than the pixel value of the reference pixel. If not, the pixel value of the pixel is adjusted to 0.
[0182] Step S308: Based on the preset first edge intensity threshold and second edge intensity threshold, adjust the pixel values of each pixel in the intermediate edge image to obtain the edge image of the X-ray image.
[0183] Step S308 is the same as step S104 described above, and will not be repeated here.
[0184] Since the first gradient value represents the rate of change of a pixel's value in the horizontal direction within its first preset neighborhood, and the second gradient value represents the rate of change of a pixel's value in the vertical direction within its first preset neighborhood, the gradient direction corresponding to a pixel can be accurately determined based on the first and second gradient values. Furthermore, after obtaining the gradient direction, reference pixels can be determined for pixels with various gradient directions through pre-divided angular partitions, and the pixel values of pixels corresponding to various gradient directions can be adjusted based on these reference points.
[0185] See Figure 4 , Figure 4 This is a flowchart illustrating the fourth image edge extraction method provided in an embodiment of the present invention. The method includes the following steps S401-S407.
[0186] Step S401: Acquire X-ray image.
[0187] Step S402: Extract edge features from the X-ray image to obtain an initial edge image.
[0188] Step S403: For each pixel in the initial edge image, obtain the gradient direction corresponding to the pixel based on the pixel value of the pixel and the pixel values of the pixels in the first preset neighborhood of the pixel. Adjust the pixel value of the pixel according to the obtained gradient direction to obtain the intermediate edge image.
[0189] Step S404: Based on the preset first edge intensity threshold and second edge intensity threshold, adjust the pixel values of each pixel in the intermediate edge image to obtain the edge image of the X-ray image.
[0190] Steps S401-S404 above are the same as those described above. Figure 1 In the illustrated embodiment, steps S101-S104 are the same and will not be repeated here.
[0191] Following steps S401-S401 above, the pixel values of each pixel in the edge image of the X-ray image are adjusted through steps S405-S407.
[0192] Step S405: Adjust the pixel values that are greater than the preset third edge intensity threshold to the pixel values corresponding to the edge pixels.
[0193] It should be noted that the embodiments of the present invention do not limit the specific value of the third edge intensity threshold. The third edge intensity threshold can be determined by the staff based on the characteristics of the X-ray image through preset experiments or other methods.
[0194] Pixels with edge strength values greater than the preset third edge strength threshold are considered to be edge pixels. Adjusting pixel values greater than the third edge strength threshold to correspond to edge pixels means identifying pixels with edge strength values as edge pixels.
[0195] The pixel value corresponding to the aforementioned edge pixel can be 255.
[0196] Step S406: Adjust the pixel values that are less than the preset fourth edge strength threshold to the pixel values corresponding to non-edge pixels.
[0197] It should be noted that the embodiments of the present invention do not limit the specific value of the fourth edge intensity threshold. The fourth edge intensity threshold can be determined by the staff based on the characteristics of the X-ray image through preset experiments or other methods.
[0198] The fourth edge strength threshold is less than the aforementioned third edge strength threshold.
[0199] Pixels with values less than the preset fourth edge strength threshold are considered to be pixels with an extremely low probability of being edge pixels. By adjusting pixel values less than the fourth edge strength threshold to correspond to non-edge pixels, these pixels are identified as non-edge pixels and thus removed from the edge image.
[0200] The pixel value corresponding to the above non-edge pixels can be 0.
[0201] Step S407: For a pixel value that is not greater than the third edge strength threshold and not less than the fourth edge strength threshold, if there is a determined edge pixel in the third preset neighborhood of the pixel corresponding to the pixel value, then adjust the pixel value to the pixel value corresponding to the edge pixel.
[0202] The size of the third preset neighborhood can be set by staff based on experience. The size of the third preset neighborhood can be the same as any one or more of the aforementioned first preset neighborhood or the aforementioned second preset neighborhood, or it can be different from both the aforementioned first preset neighborhood and the aforementioned second preset neighborhood.
[0203] A pixel with a value not greater than the third edge strength threshold and not less than the fourth edge strength threshold may or may not be an edge pixel.
[0204] If a known edge pixel exists within the third preset neighborhood of the aforementioned pixel, then the pixel is adjacent to the known edge pixel, and therefore the aforementioned pixel can be identified as an edge pixel. This makes the identified edge pixels more continuous.
[0205] As can be seen from the above, after obtaining the edge image, a double threshold hysteresis processing is performed on each pixel in the edge image based on the third edge intensity threshold and the fourth edge intensity threshold. This can further identify pixels with a higher probability of being edge pixels as edge pixels, while eliminating redundant pixels with a lower probability of being edge pixels, further reducing the interference of the above pixels in the edge image, and making the edge contour in the edge image clearer.
[0206] In addition, edge extension processing was performed on the edge image. Specifically, for pixel values that are not greater than the third edge intensity threshold and not less than the fourth edge intensity threshold, it is determined whether the pixel value should be adjusted to the pixel value corresponding to the edge pixel by judging whether there are any known edge pixels in the third preset neighborhood of the pixel corresponding to the pixel value. This helps to make the determined edge pixels more continuous and improves the quality of the obtained edge image.
[0207] The following is combined Figure 5 , Figure 6 as well as Figure 7 The advantages of the edge image obtained by applying the solution provided in the embodiments of the present invention compared with the edge image obtained by applying the solution in the prior art are explained.
[0208] in, Figure 5 An X-ray image of the human spine. Figure 6 To extract the edge image using existing image edge extraction methods, Figure 7The edge image is obtained by applying the image edge extraction method provided in the embodiments of the present invention.
[0209] The above Figure 6 as well as Figure 7 All are aimed at Figure 5 The edge image is obtained by edge extraction of the X-ray image shown.
[0210] It can be seen that, Figure 5 The X-ray image shown contains shadows of other bones, tissues, markers, and other irrelevant objects, in addition to the human spine.
[0211] exist Figure 6 As shown in the edge image, due to the influence of other bones and tissues in the X-ray image of the human spine region, the edge image contains not only the outline of the main part of the spine, but also many interfering lines or points caused by other bones and tissues in the aforementioned X-ray image.
[0212] and Figure 6 In comparison, the edge image extracted using the image edge extraction method provided in this embodiment of the invention... Figure 7 In this image, not only is the outline of the main body of the spine more complete and clearer, but it also basically does not contain any interfering lines or points caused by other bones and tissues in the X-ray image, effectively reducing the impact of other bones and tissues on edge extraction of X-ray images.
[0213] In summary, the method provided in this invention for edge extraction of X-ray images reduces interference from irrelevant content, resulting in high-precision edge images with less interference and clearer, more complete edge contours. This facilitates physicians' analysis of conditions based on the obtained high-precision edge images and improves the accuracy of subsequent medical image registration based on these high-precision edge images.
[0214] Corresponding to the above-described image edge extraction method, this embodiment of the invention also provides an image edge extraction device.
[0215] See Figure 8 , Figure 8 The first image edge extraction device provided in the embodiments of the present invention includes the following modules 801-804.
[0216] Image acquisition module 801 is used to acquire X-ray images;
[0217] The edge feature extraction module 802 is used to extract edge features from the X-ray image to obtain an initial edge image;
[0218] The first pixel value adjustment module 803 is used to obtain the gradient direction corresponding to each pixel in the initial edge image based on the pixel value of the pixel and the pixel values of the pixels in the first preset neighborhood of the pixel, and adjust the pixel value of the pixel according to the obtained gradient direction to obtain the intermediate edge image.
[0219] The second pixel value adjustment module 804 is used to adjust the pixel value of each pixel in the intermediate edge image based on a preset first edge strength threshold and a second edge strength threshold, so as to obtain the edge image of the X-ray image.
[0220] As can be seen from the above, when using the image edge extraction method provided in this embodiment of the invention to extract edges from X-ray images, the edge features of the X-ray image are first extracted to obtain an initial edge image. For each pixel in the initial edge image, the gradient direction corresponding to each pixel is obtained based on the pixel value of each pixel in the initial edge image and the pixel value of each pixel in the first preset neighborhood. Since the gradient direction represents the direction in which the pixel value of each pixel changes at the largest rate in the first preset neighborhood, adjusting the pixel value of each pixel according to the obtained gradient direction is beneficial to eliminating redundant pixels with non-maximum pixel values in the first preset neighborhood, retaining pixels with larger pixel values in the gradient direction, reducing interference information in the initial edge image, and obtaining an intermediate edge image with clearer edge contours.
[0221] Then, based on the preset first edge strength threshold and second edge strength threshold, the pixel values of each pixel in the intermediate edge image are adjusted again. This increases or decreases the pixel values of each pixel, making the distinction between light and dark in the intermediate edge image more obvious, further reducing the interference information in the intermediate edge image, making the edge contour in the adjusted edge image clearer, and improving the accuracy of the edge image of the obtained X-ray image.
[0222] In one embodiment of the present invention, the second pixel value adjustment module 804 is specifically used to adjust the pixel value of each pixel in the intermediate edge image in the following manner to obtain the edge image of the X-ray image:
[0223] If the pixel value of the pixel is greater than a preset first edge strength threshold, then the pixel value of the pixel is increased by a first preset value; if the pixel value of the pixel is less than a preset second edge strength threshold, then the pixel value of the pixel is decreased by a second preset value, wherein the first edge strength threshold is greater than the second edge strength threshold.
[0224] In X-ray images, edge pixels have higher pixel values, while non-edge pixels have lower pixel values. Therefore, for each pixel in the intermediate edge image, a first preset value is added to the pixel values of pixels with values greater than a first threshold, making these pixels brighter and clearer in the intermediate edge image, thus improving the clear display of edge pixels. Conversely, a second preset value is subtracted from the pixel values of pixels with values less than the first threshold, making these pixels darker and blurrier in the intermediate edge image, thus suppressing or eliminating non-edge pixels. This improves the contrast between light and dark areas of edge and non-edge pixels in the intermediate edge image, resulting in clearer edge contours in the final edge image and enhancing the accuracy of the edge image in the obtained X-ray image.
[0225] In one embodiment of the present invention, the apparatus further includes: a third pixel value adjustment module, configured to adjust the pixel values of each pixel in the edge image of the X-ray image in the following manner after the second pixel value adjustment module 804 adjusts the pixel values:
[0226] Adjust pixel values that are greater than the preset third edge strength threshold to the pixel values corresponding to the edge pixels;
[0227] Pixel values that are less than a preset fourth edge strength threshold are adjusted to the pixel values corresponding to non-edge pixels, wherein the third edge strength threshold is greater than the fourth edge strength threshold;
[0228] For a pixel value that is not greater than the third edge strength threshold and not less than the fourth edge strength threshold, if there is a determined edge pixel in the third preset neighborhood of the pixel corresponding to the pixel value, then the pixel value is adjusted to the pixel value corresponding to the edge pixel.
[0229] As can be seen from the above, after obtaining the edge image, a double threshold hysteresis processing is performed on each pixel in the edge image based on the third edge intensity threshold and the fourth edge intensity threshold. This can further identify pixels with a higher probability of being edge pixels as edge pixels, while eliminating redundant pixels with a lower probability of being edge pixels, further reducing the interference of the above pixels in the edge image, and making the edge contour in the edge image clearer.
[0230] In addition, edge extension processing was performed on the edge image. Specifically, for pixel values that are not greater than the third edge intensity threshold and not less than the fourth edge intensity threshold, it is determined whether the pixel value should be adjusted to the pixel value corresponding to the edge pixel by judging whether there are any known edge pixels in the third preset neighborhood of the pixel corresponding to the pixel value. This helps to make the determined edge pixels more continuous and improves the quality of the obtained edge image.
[0231] See Figure 9 , Figure 9 The second image edge extraction device provided in the embodiments of the present invention includes the following modules 901-905.
[0232] Image acquisition module 901 is used to acquire X-ray images;
[0233] The gradient value acquisition submodule 902 is used to obtain the first gradient value corresponding to each pixel in the horizontal direction and the second gradient value corresponding to each pixel in the vertical direction based on the pixel value of each pixel in the X-ray image and the pixel value of each pixel in the first preset neighborhood of each pixel.
[0234] The edge intensity acquisition submodule 903 is used to obtain the edge intensity corresponding to each pixel point according to the first gradient value and the second gradient value corresponding to each pixel point in the X-ray image, and to obtain an initial edge image generated based on the obtained edge intensity.
[0235] The first pixel value adjustment module 904 is used to obtain the gradient direction corresponding to each pixel in the initial edge image, which is determined based on the pixel value of the pixel and the pixel values of the pixels in the first preset neighborhood of the pixel, and adjust the pixel value of the pixel according to the obtained gradient direction to obtain the intermediate edge image.
[0236] The second pixel value adjustment module 905 is used to adjust the pixel value of each pixel in the intermediate edge image based on a preset first edge strength threshold and a second edge strength threshold, so as to obtain the edge image of the X-ray image.
[0237] Since the first gradient value represents the rate of change of the pixel value in the horizontal direction within its first preset neighborhood, and the second gradient value represents the rate of change of the pixel value in the vertical direction within its first preset neighborhood, and the edge strength can be measured by the rate of change of the pixel value, calculating the gradients in both the horizontal and vertical directions and obtaining the edge strength of the pixel based on the gradients in these two directions can more accurately measure the difference between the pixel value of the pixel and the pixel values of the pixels in its first preset neighborhood, thus improving the accuracy of the obtained edge strength.
[0238] See Figure 10 , Figure 10 The third image edge extraction device provided in the embodiments of the present invention includes the following modules 1001-1008.
[0239] Image acquisition module 1001 is used to acquire X-ray images;
[0240] The gradient value acquisition submodule 1002 is used to obtain the first gradient value of each pixel in the horizontal direction and the second gradient value in the vertical direction based on the pixel value of each pixel in the X-ray image and the pixel value of each pixel in the first preset neighborhood of each pixel.
[0241] The edge intensity acquisition submodule 1003 is used to obtain the edge intensity corresponding to each pixel point according to the first gradient value and the second gradient value corresponding to each pixel point in the X-ray image, and to obtain an initial edge image generated based on the obtained edge intensity.
[0242] The gradient direction acquisition submodule 1004 is used to obtain the gradient direction corresponding to each pixel in the initial edge image based on the first gradient value and the second gradient value corresponding to the pixel.
[0243] The target angle partition determination submodule 1005 is used to determine the target angle partition to which the obtained gradient direction belongs from the preset angle partitions, wherein each angle partition includes two sub-angle partitions that are centrally symmetrical.
[0244] The reference pixel point determination submodule 1006 determines the reference pixel point corresponding to the pixel point from the second preset neighborhood of the pixel point in each sub-angle partition included in the target angle partition;
[0245] The pixel value adjustment submodule 1007 is used to adjust the pixel value of a pixel based on the pixel value of a determined reference pixel to obtain the intermediate edge image.
[0246] The second pixel value adjustment module 1008 is used to adjust the pixel value of each pixel in the intermediate edge image based on a preset first edge strength threshold and a second edge strength threshold, so as to obtain the edge image of the X-ray image.
[0247] Since the first gradient value represents the rate of change of a pixel's value in the horizontal direction within its first preset neighborhood, and the second gradient value represents the rate of change of a pixel's value in the vertical direction within its first preset neighborhood, the gradient direction corresponding to a pixel can be accurately determined based on the first and second gradient values. Furthermore, after obtaining the gradient direction, reference pixels can be determined for pixels with various gradient directions through pre-divided angular partitions, and the pixel values of pixels corresponding to various gradient directions can be adjusted based on these reference points.
[0248] In one embodiment of the present invention, the pixel value adjustment submodule 1007 is specifically used to determine the interpolation ratio corresponding to each reference pixel in each sub-angle partition of the target angle partition according to the first gradient value and the second gradient value corresponding to the pixel; for each sub-angle partition of the target angle partition, the pixel interpolation is calculated based on the pixel value of each reference pixel and the corresponding interpolation ratio; if the pixel interpolation corresponding to each sub-angle partition of the target angle partition is greater than the pixel value of the pixel, the pixel value of the pixel is adjusted to 0; and the intermediate edge image is obtained based on the adjustment result.
[0249] Since the gradient interpolation corresponding to a pixel represents the possible maximum value in the gradient direction within the second preset neighborhood of that pixel, if the pixel value is less than any pixel interpolation value, it means that the pixel value is not a maximum value within its second preset neighborhood. Adjusting the pixel value to 0 helps to eliminate pixels with non-maximum values within the first preset neighborhood, reducing redundant pixels in the initial edge image. Therefore, by performing non-maximum suppression processing on the pixels in the initial edge image, interference information in the initial edge image is reduced, resulting in clearer edge contours in the obtained intermediate edge image.
[0250] This invention also provides an electronic device, such as... Figure 11 As shown, it includes a processor 1101, a communication interface 1102, a memory 1103, and a communication bus 1104. The processor 1101, communication interface 1102, and memory 1103 communicate with each other via the communication bus 1104.
[0251] Memory 1103 is used to store computer programs;
[0252] The processor 1101 is used to execute the program stored in the memory 1103 to implement the image edge extraction method provided in the embodiments of the present invention.
[0253] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0254] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0255] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0256] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0257] In another embodiment of the present invention, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the image edge extraction method provided in the embodiments of the present invention.
[0258] In another embodiment of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute the image edge extraction method provided in the embodiments of the present invention.
[0259] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0260] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0261] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, electronic devices, and storage media are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0262] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.
Claims
1. An image edge extraction method, characterized in that, The method includes: Acquire X-ray images; Edge features are extracted from the X-ray image to obtain an initial edge image; For each pixel in the initial edge image, the gradient direction corresponding to the pixel is obtained based on the pixel value of the pixel and the pixel values of the pixels in the first preset neighborhood of the pixel. The pixel value of the pixel is adjusted according to the obtained gradient direction to obtain the intermediate edge image. Based on a preset first edge strength threshold and a second edge strength threshold, the pixel values of each pixel in the intermediate edge image are adjusted to obtain the edge image of the X-ray image; The step of adjusting the pixel values of each pixel in the intermediate edge image based on a preset first edge strength threshold and a second edge strength threshold to obtain the edge image of the X-ray image includes: For each pixel in the intermediate edge image, the pixel value of that pixel is adjusted in the following way to obtain the edge image of the X-ray image: If the pixel value of the pixel is greater than the preset first edge strength threshold, then the pixel value of the pixel is incremented by the first preset value; If the pixel value of the pixel is less than the preset second edge strength threshold, then the pixel value of the pixel is subtracted from the second preset value, or the pixel value of the pixel is set to 0, wherein the first edge strength threshold is greater than the second edge strength threshold; Adjust the pixel values of each pixel in the edge image of the X-ray image as follows: Adjust pixel values that are greater than the preset third edge strength threshold to the pixel values corresponding to the edge pixels; Pixel values that are less than a preset fourth edge strength threshold are adjusted to the pixel values corresponding to non-edge pixels, wherein the third edge strength threshold is greater than the fourth edge strength threshold; For a pixel value that is not greater than the third edge strength threshold and not less than the fourth edge strength threshold, if there is a determined edge pixel in the third preset neighborhood of the pixel corresponding to the pixel value, then the pixel value is adjusted to the pixel value corresponding to the edge pixel.
2. The method according to claim 1, characterized in that, The step of extracting edge features from the X-ray image to obtain an initial edge image includes: Based on the pixel values of each pixel in the X-ray image and the pixel values of the pixels in the first preset neighborhood of each pixel, the first gradient value corresponding to each pixel in the horizontal direction and the second gradient value corresponding to each pixel in the vertical direction are obtained. Based on the first gradient value and the second gradient value corresponding to each pixel in the X-ray image, the edge intensity corresponding to each pixel is obtained, and an initial edge image is generated based on the obtained edge intensity.
3. The method according to claim 2, characterized in that, The step of obtaining the gradient direction corresponding to the pixel, determined based on the pixel value of the pixel and the pixel values of pixels in the first preset neighborhood of the pixel, and adjusting the pixel value of the pixel according to the obtained gradient direction, includes: The gradient direction corresponding to the pixel is obtained based on the first gradient value and the second gradient value corresponding to the pixel. From the preset angle partitions, determine the target angle partition to which the obtained gradient direction belongs, wherein each angle partition includes two sub-angle partitions that are centrally symmetrical; From the second preset neighborhood of the pixel in each sub-angle partition included in the target angle partition, the reference pixel corresponding to the pixel is determined respectively. Adjust the pixel value of the reference pixel based on the pixel value of the reference pixel.
4. The method according to claim 3, characterized in that, The step of adjusting the pixel value of a reference pixel based on the determined pixel value includes: Based on the first gradient value and the second gradient value corresponding to the pixel, determine the interpolation ratio corresponding to each reference pixel in each sub-angle partition of the target angle partition; For each sub-angle partition of the target angle partition, pixel interpolation is calculated based on the pixel value of each reference pixel and the corresponding interpolation ratio; If the pixel interpolation value corresponding to each sub-angle partition of the target angle partition is greater than the pixel value of that pixel, then the pixel value of that pixel is adjusted to 0.
5. An image edge extraction device, characterized in that, The device includes: The image acquisition module is used to acquire X-ray images; An edge feature extraction module is used to extract edge features from the X-ray image to obtain an initial edge image; The first pixel value adjustment module is used to obtain the gradient direction corresponding to each pixel in the initial edge image, which is determined based on the pixel value of the pixel and the pixel values of the pixels in the first preset neighborhood of the pixel, and adjust the pixel value of the pixel according to the obtained gradient direction to obtain the intermediate edge image. The second pixel value adjustment module is used to adjust the pixel value of each pixel in the intermediate edge image based on a preset first edge strength threshold and a second edge strength threshold, so as to obtain the edge image of the X-ray image. The second pixel value adjustment module is specifically used to adjust the pixel value of each pixel in the intermediate edge image in the following manner to obtain the edge image of the X-ray image: If the pixel value of the pixel is greater than the preset first edge strength threshold, then the pixel value of the pixel is incremented by the first preset value; if the pixel value of the pixel is less than the preset second edge strength threshold, then the pixel value of the pixel is subtracted by the second preset value, or the pixel value of the pixel is set to 0, wherein the first edge strength threshold is greater than the second edge strength threshold; The device further includes: The third pixel value adjustment module is used to adjust the pixel values of each pixel in the edge image of the X-ray image after the second pixel value adjustment module has adjusted the pixel values, in the following manner: Adjust pixel values that are greater than the preset third edge strength threshold to the pixel values corresponding to the edge pixels; Pixel values that are less than a preset fourth edge strength threshold are adjusted to the pixel values corresponding to non-edge pixels, wherein the third edge strength threshold is greater than the fourth edge strength threshold; For a pixel value that is not greater than the third edge strength threshold and not less than the fourth edge strength threshold, if there is a determined edge pixel in the third preset neighborhood of the pixel corresponding to the pixel value, then the pixel value is adjusted to the pixel value corresponding to the edge pixel.
6. The apparatus according to claim 5, characterized in that, The edge feature extraction module includes: The gradient value acquisition submodule is used to obtain the first gradient value of each pixel in the horizontal direction and the second gradient value in the vertical direction based on the pixel value of each pixel in the X-ray image and the pixel value of each pixel in the first preset neighborhood of each pixel. The edge intensity acquisition submodule is used to obtain the edge intensity corresponding to each pixel point according to the first gradient value and the second gradient value corresponding to each pixel point in the X-ray image, and to obtain an initial edge image generated based on the obtained edge intensity.
7. The apparatus according to claim 6, characterized in that, The first pixel value adjustment module includes: The gradient direction acquisition submodule is used to obtain the gradient direction corresponding to each pixel in the initial edge image based on the first gradient value and the second gradient value corresponding to the pixel. The target angle partition determination submodule is used to determine the target angle partition to which the obtained gradient direction belongs from the preset angle partitions, wherein each angle partition includes two sub-angle partitions that are centrally symmetrical. The reference pixel point determination submodule determines the reference pixel point corresponding to the pixel point from the second preset neighborhood of the pixel point in each sub-angle partition included in the target angle partition; The pixel value adjustment submodule is used to adjust the pixel value of a given reference pixel to obtain the intermediate edge image.
8. The apparatus according to claim 7, characterized in that, The pixel value adjustment submodule is specifically used to determine the interpolation ratio corresponding to each reference pixel in each sub-angle partition of the target angle partition based on the first gradient value and the second gradient value corresponding to the pixel; for each sub-angle partition of the target angle partition, the pixel interpolation is calculated based on the pixel value of each reference pixel and the corresponding interpolation ratio; if the pixel interpolation corresponding to each sub-angle partition of the target angle partition is greater than the pixel value of the pixel, the pixel value of the pixel is adjusted to 0; and the intermediate edge image is obtained based on the adjustment result.
9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the method described in any one of claims 1-4.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-4.