A method and apparatus for digitizing paper electrocardiograms
By preprocessing, separating, and refining paper electrocardiograms (ECGs), they can be converted into electronic ECGs, solving the problem of insufficient size of electronic ECGs and promoting the development of automated ECG analysis.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TSINGHUA UNIVERSITY
- Filing Date
- 2022-07-20
- Publication Date
- 2026-06-23
AI Technical Summary
In existing technologies, the amount of electronic electrocardiogram (ECG) data is insufficient, making it difficult to achieve automatic ECG abnormality analysis, especially to identify specific types of ECG abnormalities and analyze ECG abnormalities other than specific types.
This paper provides a method for digitizing paper electrocardiograms (ECGs). Through preprocessing, lead region separation, refinement, and lead dimension connection, the paper ECG is converted into an electronic ECG. The method includes techniques such as noise pixel removal, stamp removal, background grid line removal, eight-neighbor sparse outlier removal algorithm, and pre-stored refinement algorithm.
This solved the problem of insufficient electronic electrocardiogram (ECG) data, promoted the development of the field of automated ECG analysis, realized the digital conversion of paper ECGs, and provided data support for scientific research and clinical analysis.
Smart Images

Figure CN115272112B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of automated electrocardiogram (ECG) analysis technology, and more particularly to a method and apparatus for digitizing paper ECGs. Background Technology
[0002] Electrocardiography (ECG) can most directly reflect the electrical activity of the heart and is the most common clinical technique used for analyzing cardiac abnormalities.
[0003] Currently, there are many computer-aided methods that utilize electronic electrocardiogram (ECG) datasets to achieve automatic ECG abnormality analysis, and the development of deep learning has further promoted progress in this field.
[0004] However, to achieve automated ECG anomaly analysis using the above methods, a sufficient amount of sample data in the electronic ECG dataset is required. Currently available free and open-source databases have a far from sufficient volume of electronic ECG data, and there are gaps in the availability of specific types of electronic ECGs. This makes it difficult to identify specific types of ECG anomalies and to accurately analyze ECG anomalies other than those specific types.
[0005] It is worth noting that paper electrocardiograms (ECGs) are generated daily in hospitals across the country. Fully utilizing this vast collection of paper ECGs would undoubtedly provide data support for scientific research and clinical analysis by doctors, maximizing the advancement of the ECG analysis field. Therefore, it is necessary to develop a method for digitizing paper ECGs. Summary of the Invention
[0006] The purpose of this invention is to provide a method and apparatus for digitizing paper electrocardiograms (ECGs). By digitizing the effective information of the ECG signals in paper ECGs, the paper ECGs continuously generated by hospitals can be converted into electronic ECGs. This solves the problem of difficulties in achieving automatic ECG abnormality analysis due to the insufficient volume of electronic ECGs, and promotes the development of the field of automatic ECG analysis.
[0007] In a first aspect, the present invention provides a method for digitizing a paper electrocardiogram, the method comprising:
[0008] The electronic image of the paper electrocardiogram containing twelve lead regions is preprocessed to obtain the electrocardiogram image;
[0009] Separate the individual lead regions of the electrocardiogram;
[0010] Based on the eight-neighborhood sparse outlier removal algorithm and the pre-stored thinning algorithm, the electrocardiogram images of each lead region are thinned to obtain the electrocardiogram waveform curves of each lead region.
[0011] The electrocardiogram waveforms of each lead region are connected along the lead dimension to obtain the digital result of the paper electrocardiogram.
[0012] According to the paper electrocardiogram digitization method provided by the present invention, the preprocessing includes at least: noise pixel removal, stamp removal, and background grid line removal.
[0013] According to the paper electrocardiogram digitization method provided by the present invention, the electronic image of the paper electrocardiogram is preprocessed to obtain an electrocardiogram image, including:
[0014] Gaussian filtering is used to remove noise pixels from the electronic image;
[0015] Based on RGB channel separation technology, the grayscale image of the electronic image after filtering out noise pixels is obtained in the R channel;
[0016] Perform foreground-background separation on the grayscale image to obtain a binarized grayscale image with the stamp removed;
[0017] The positions of the background grid lines are obtained by processing the grayscale image corresponding to the electronic image using binary morphological operations.
[0018] Based on the location of the background grid lines, the background grid lines in the binarized grayscale image are removed to obtain the electrocardiogram image.
[0019] According to the paper electrocardiogram digitization method provided by the present invention, the separation of the individual lead regions of the electrocardiogram image includes:
[0020] The location of each lead region in the electrocardiogram curve image is marked manually.
[0021] Based on the location markers, the separation of each lead region in the electrocardiogram curve image is achieved.
[0022] According to the paper electrocardiogram digitization method provided by the present invention, the electrocardiogram images of each lead region are refined based on the eight-neighborhood sparse outlier removal algorithm and a pre-stored refinement algorithm to obtain the electrocardiogram waveform curves of each lead region, including:
[0023] For any lead region's electrocardiogram image, based on the eight-neighborhood sparse outlier removal algorithm, noise pixels in the electrocardiogram image of that lead region are removed;
[0024] Using a pre-stored thinning algorithm, the electrocardiogram image after removing noise pixels is thinned to obtain the electrocardiogram waveform curve of any one of the lead regions.
[0025] According to the paper electrocardiogram digitization method provided by the present invention, the removal of noisy pixels in the electrocardiogram of any lead region based on the eight-neighborhood sparse outlier removal algorithm includes:
[0026] The foreground pixels of the electrocardiogram traversing any one of the lead regions along the vertical scan line;
[0027] Foreground pixels that meet the first set condition are identified as noise pixels.
[0028] Remove the noisy pixels;
[0029] The first setting condition is that the number of foreground pixels contained in the eight-neighbor area is less than a preset threshold.
[0030] According to the paper electrocardiogram digitization method provided by the present invention, the step of using a pre-stored thinning algorithm to thin the electrocardiogram image after removing noise pixels to obtain the electrocardiogram waveform curve of any one lead region includes:
[0031] An array is used to represent the foreground pixels contained in the electrocardiogram image after removing noise pixels;
[0032] The array of foreground pixels is traversed in ascending order of their horizontal coordinates, and the vertical coordinate of the foreground pixel that has a unique correspondence with the horizontal coordinate of each traversed foreground pixel is determined.
[0033] Add the coordinate pairs consisting of the x-coordinate and y-coordinate of the foreground pixel that have a unique correspondence to the foreground pixel list to generate a refined foreground pixel list.
[0034] Pixel fitting is performed on the refined foreground pixel list to obtain the electrocardiogram waveform curve of any one of the lead regions;
[0035] The foreground pixel list is initially empty, and the value of each foreground pixel in the array is its position coordinate in the electrocardiogram after the removal of noise pixels.
[0036] According to the paper electrocardiogram digitization method provided by the present invention, determining the ordinate of the foreground pixel that has a unique correspondence with the abscissa of each traversed foreground pixel includes:
[0037] When the x-coordinate of the foreground pixel point being traversed has only one corresponding y-coordinate in the array, it is determined that there is a unique correspondence between the unique y-coordinate of the foreground pixel point and the x-coordinate of the foreground pixel point being traversed.
[0038] When the x-coordinate of the foreground pixel point being traversed has multiple y-coordinates corresponding to it in the array, it is determined whether the maximum distance difference between the multiple y-coordinates of the foreground pixel points is not greater than a first preset distance difference, and based on the determination result, the y-coordinate of the foreground pixel point that has a unique correspondence with the x-coordinate of the foreground pixel point being traversed is determined.
[0039] According to the paper electrocardiogram digitization method provided by the present invention, the step of determining the ordinate of the foreground pixel that has a unique correspondence with the abscissa of the traversed foreground pixel includes:
[0040] If the judgment result is yes, calculate the average value of the ordinates of the multiple foreground pixels;
[0041] It is determined that there is a unique correspondence between the average value and the x-coordinate of the foreground pixel point being traversed.
[0042] According to the paper electrocardiogram digitization method provided by the present invention, the step of determining the ordinate of the foreground pixel that has a unique correspondence with the abscissa of the traversed foreground pixel according to the judgment result further includes:
[0043] If the judgment result is negative, obtain the ordinate of the foreground pixel that has a unique correspondence with the foreground pixel whose x-coordinate is one before the foreground pixel in the traversal order.
[0044] Calculate the difference between the ordinate of each of the plurality of foreground pixels and the obtained ordinate of the foreground pixels;
[0045] The ordinates of the foreground pixels whose differences are within a preset range are assigned to a first list, and the ordinates of the foreground pixels whose differences are not within a preset range are assigned to a second list.
[0046] If the number of foreground pixels in the second list is greater than the preset number, it is determined that there is a unique correspondence between the ordinate of the foreground pixel with the largest difference in the second list and the abscissa of the traversed foreground pixels.
[0047] If the number of foreground pixels in the second list is not greater than a preset number, it is determined that there is a unique correspondence between the average value of the ordinate of the foreground pixels in the first list and the x-coordinate of the traversed foreground pixels.
[0048] According to the paper electrocardiogram digitization method provided by the present invention, the step of connecting the electrocardiogram waveform curves of each lead region along the lead dimension to obtain the digitized result of the paper electrocardiogram includes:
[0049] The electrocardiogram waveforms of each lead region were sequentially normalized and clipped to the same length.
[0050] The ECG waveform curves of each lead region after normalization and equal-length cropping are connected to obtain the digital result of the paper ECG.
[0051] In a second aspect, the present invention provides a paper-based electrocardiogram digitization device, the device comprising:
[0052] The preprocessing module is used to preprocess the electronic image of a paper electrocardiogram containing twelve lead regions to obtain an electrocardiogram image;
[0053] A separation module is used to separate the various lead regions of the electrocardiogram;
[0054] The thinning processing module is used to thin the electrocardiogram images of each lead region based on the eight-neighbor sparse outlier removal algorithm and the pre-stored thinning algorithm to obtain the electrocardiogram waveform curves of each lead region.
[0055] The connection module is used to connect the electrocardiogram waveform curves of each lead region along the lead dimension to obtain the digital result of the paper electrocardiogram.
[0056] This invention provides a method and apparatus for digitizing paper electrocardiograms (ECGs). The method involves preprocessing and separating the electronic image of a paper ECG containing twelve lead regions to isolate the corresponding ECG curve pixels for each lead region. Then, the ECG curve pixels for each lead region are refined to obtain the ECG curve for each lead region. Finally, the ECG curves for each lead region are connected along the lead dimension to obtain the ECG waveform curves for all twelve leads. By digitizing the effective ECG signal information from the paper ECG, the continuously generated paper ECGs from hospitals are converted into electronic ECGs, solving the problem of insufficient electronic ECG volume that hinders automated ECG anomaly analysis and promoting the development of the field of automated ECG analysis. Attached Figure Description
[0057] To more clearly illustrate the technical solutions in this 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 some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0058] Figure 1 This is a flowchart of a paper electrocardiogram digitization method provided by the present invention;
[0059] Figure 2This is an example diagram of common structural elements for morphological operations provided by the present invention;
[0060] Figure 3 This is an example diagram of the morphological operation rectangular array structure element provided by the present invention;
[0061] Figure 4 This is a partially enlarged schematic diagram of the electrocardiogram waveform curve in the lead area provided by the present invention;
[0062] Figure 5 This is an example image of the digitized results of a paper electrocardiogram for Stanford type A acute aortic dissection provided by the present invention;
[0063] Figure 6 This is an example diagram of the digitized results of a paper electrocardiogram for ST-segment elevation myocardial infarction provided by the present invention;
[0064] Figure 7 This is a schematic diagram of the training loss change curve of the interpretation model provided by the present invention;
[0065] Figure 8 This is a schematic diagram of the interpretation accuracy variation curve of the interpretation model provided by the present invention;
[0066] Figure 9 This is a structural diagram of a paper-based electrocardiogram digitization device provided by the present invention;
[0067] Figure 10 This is a schematic diagram of the electronic device structure for implementing the paper electrocardiogram digitization method provided by the present invention. Detailed Implementation
[0068] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0069] The following is combined Figures 1 to 10 This invention describes a method and apparatus for digitizing paper electrocardiograms.
[0070] In a first aspect, the present invention provides a method for digitizing paper electrocardiograms, such as... Figure 1 As shown, the method includes:
[0071] S11. Preprocess the electronic image of the paper electrocardiogram containing twelve lead regions to obtain the electrocardiogram image;
[0072] Since computer-aided technology is needed to digitize the paper electrocardiogram (ECG), it is necessary to acquire an electronic image of the paper ECG. Methods for obtaining this electronic image include, but are not limited to, scanning. Furthermore, this invention employs preprocessing to remove information such as grid lines and stamps that hinder ECG curve analysis from the electronic image of the paper ECG.
[0073] S12. Separate the individual lead regions of the electrocardiogram;
[0074] A twelve-lead electrocardiograph includes six limb leads and six chest leads. The limb leads include three standard limb leads (I, II, and III) and three augmented limb leads (aVR, aVL, and aVF). The chest leads include six leads: V1, V2, V3, V4, V5, and V6. The limb leads are placed in the right arm, left arm, and left leg, respectively. In the chest leads, lead V1 is placed at the right sternal border in the fourth intercostal space; lead V2 is placed at the left sternal border in the fourth intercostal space; lead V3 is placed at the midpoint of the line connecting leads V2 and V4; lead V4 is placed at the level of the fifth intercostal space along the left midclavicular line; lead V5 is placed at the same level as lead V4 along the left anterior axillary line; and lead V6 is placed at the same level as lead V4 along the left midaxillary line.
[0075] Correspondingly, the electrocardiogram waveform curves of the twelve-lead ECG chart correspond to twelve lead regions, and the starting position of each lead region has lead markings from the ECG machine. Therefore, the separation of the ECG images can be achieved based on the lead markings of the twelve lead regions.
[0076] S13. Based on the eight-neighborhood sparse outlier removal algorithm and the pre-stored thinning algorithm, the electrocardiogram images of each lead region are thinned to obtain the electrocardiogram waveform curves of each lead region.
[0077] This involves refining and fitting the pixels of the electrocardiogram images in each lead region to obtain the pixel information of the electrocardiogram waveform representing each lead region.
[0078] S14. Connect the ECG waveform curves of each lead region along the lead dimension to obtain the digital result of the paper ECG.
[0079] It is understandable that connecting the ECG waveform curves of the 12 lead regions along the lead dimension is equivalent to the reverse operation of separating the individual lead regions of the ECG image.
[0080] This invention provides a method for digitizing paper electrocardiograms (ECGs). The method involves preprocessing the electronic image of the paper ECG and separating the lead regions to isolate the corresponding ECG curve pixels for each lead region. Then, the ECG curve pixels for each lead region are refined to obtain the ECG curve for each lead region. Finally, the ECG curves for each lead region are connected along the lead dimension to obtain an ECG waveform curve containing twelve lead regions. By digitizing the effective ECG signal information from the paper ECG, the continuously generated paper ECGs from hospitals can be converted into electronic ECGs, solving the problem of insufficient electronic ECG volume that hinders automated ECG anomaly analysis and promoting the development of the field of automated ECG analysis.
[0081] Based on the above embodiments, as an optional embodiment, the preprocessing includes at least: noise pixel removal, stamp removal, and background grid line removal.
[0082] Noise is introduced during the digitization of paper electrocardiograms (ECGs), typically existing as isolated pixels or pixel blocks. This noise, along with inherent features of the paper ECG such as stamps and background grid lines, creates a strong visual effect in the electronic image, interfering with the analysis of the ECG curves across the twelve leads. Therefore, this invention removes noise, stamps, and background grid lines from the electronic image of the paper ECG during the preprocessing stage. This ensures that the preprocessed ECG image contains only the most effective information representing the ECG signal, laying the foundation for subsequent processing.
[0083] Based on the above embodiments, as an optional embodiment, the electronic image of the paper electrocardiogram is preprocessed to obtain an electrocardiogram image, including:
[0084] Gaussian filtering is used to remove noise pixels from the electronic image;
[0085] Here, Gaussian filtering can be performed using the cv2.gaussianblur() function provided by OpenCV, and the size of the Gaussian kernel can be set to 5*5.
[0086] Based on RGB channel separation technology, the grayscale image of the electronic image after filtering out noise pixels is obtained in the R channel;
[0087] Perform foreground-background separation on the grayscale image to obtain a binarized grayscale image with the stamp removed;
[0088] The stamp removal operation is as follows: Separate the RGB channels of the target image; use color features to separate the foreground and background of the grayscale image of the target image under the R channel, and obtain a binary grayscale image with the stamp removed.
[0089] The splitting operation can be performed using, but is not limited to, the cv2.split() function provided by OpenCV.
[0090] Specifically, the foreground and background separation involves using the pixels of the ECG waveform and grid lines as the foreground, and the pixels corresponding to the stamp and paper as the background. In the R channel, the grayscale value of the stamp portion of the target image is close to 255, which is white; the grayscale value of the paper is also close to 255, which is gray (close to white); and the grayscale values of the ECG waveform and grid lines are close to 0, which is black. Therefore, a suitable separation threshold thresh is set, and pixels with grayscale values less than thresh are set to 0, while pixels with grayscale values greater than thresh are set to 255, resulting in a binarized grayscale image with the red stamp removed.
[0091] This article provides a method for setting the threshold, which involves using the cv2.threshold() function provided by OpenCV and combining it with the cv2.THRESH_OTSU parameter to automatically generate the threshold.
[0092] In the above threshold setting method, since the grayscale histogram of the R channel is a bimodal image (with two peaks), the threshold should be located in the valley between the two peaks as much as possible. Therefore, the parameter cv2.THRESH_OTSU can be set to valid, and the algorithm will automatically calculate the appropriate threshold based on the histogram.
[0093] The positions of the background grid lines are obtained by processing the grayscale image corresponding to the electronic image using binary morphological operations.
[0094] Specifically, the steps to determine the position of the background grid lines are as follows:
[0095] Step 1: Convert the RGB color image to a grayscale image using a grayscale conversion operation. This operation can be done, but is not limited to, using the color space conversion function cv2.cvtColor() provided by OpenCV.
[0096] Step 2: Use binary morphological operations to process the grayscale image to obtain the positions of the background grid lines. That is, first binarize the grayscale image, and then use a rectangular structuring element to perform morphological operations to determine the positions of the background grid lines. Here, the binarization operation can be done using, but is not limited to, the cv2.adaptiveThreshold function provided by OpenCV.
[0097] Among them, a structuring element (SE) consists of a series of pixel sets, and it has an element anchor point, which is generally defined as its center. Figure 2This example illustrates common structuring elements in morphological operations, with black dots serving as their anchor points. When performing morphological operations, the structuring elements are required to consist of a rectangular array. In a binary image, the foreground and background are represented by f and b, respectively. This rectangular array can be formed by adding a minimum number of background elements b to the structuring element, such as... Figure 3 Example of a morphological operation rectangular array structuring element.
[0098] The morphological operation described refers to performing a closing operation on the binarized image to detect grid lines. Taking vertical grid lines as an example, a dilation operation is first performed using a rectangular structuring element with a height of h and a width of 1 to eliminate horizontal grid lines and isolated breakpoints. Then, an erosion operation is performed using the same structuring element to connect the discontinuous vertical grid lines. Similarly, a rectangular structuring element with a height of 1 and a width of w is used to detect horizontal grid lines.
[0099] The dilation and erosion operations here can be implemented using, but are not limited to, the cv2.dilate and cv2.erode functions provided by OpenCV.
[0100] The h and w are calculated based on the height H and width W of the processed image. Specifically, by setting the scale factor, h = H / scale and w = W / scale.
[0101] Based on the location of the background grid lines, the background grid lines in the binarized grayscale image are removed to obtain the electrocardiogram image.
[0102] The grayscale value of the pixels corresponding to the detected grid lines is set to 255 for elimination.
[0103] Specifically, the grayscale value of the pixel corresponding to the grid line in the binarized grayscale image is set to 255 to eliminate the grid line.
[0104] This invention provides the optimal implementation methods for noise pixel removal, stamp removal, and background grid line removal, so as to remove useless information in the electronic image of the paper electrocardiogram more meticulously and effectively.
[0105] Based on the above embodiments, as an optional embodiment, separating the various lead regions of the electrocardiogram includes:
[0106] The location of each lead region in the electrocardiogram curve image is marked manually.
[0107] That is, this invention is based on manually marking the position of each lead in the electrocardiogram curve image using a labeling tool;
[0108] It should be noted that this invention saves the position markers of each lead for subsequent retrieval. The aforementioned annotation tools include, but are not limited to, labelimg. The position of each lead is represented by, but is not limited to, the coordinates of the upper left and lower right corners of the rectangle of each lead area. The save format of each lead position marker includes, but is not limited to, XML file format.
[0109] Based on the location markers, the separation of each lead region in the electrocardiogram curve image is achieved.
[0110] Specifically, the location information in the XML file is read to separate each lead. That is, using the coordinates of the top-left and bottom-right corners of the rectangle recorded in the XML file, the pixels corresponding to each lead are saved separately.
[0111] It is understandable that the location marking of each lead region is to enable the machine to identify each lead region and thus achieve the separation of each lead region.
[0112] This invention separates the various lead regions, laying the foundation for processing the electrocardiogram images of each lead region separately, thereby facilitating the extraction of pixel information representing the electrocardiogram curves of each lead region.
[0113] Based on the above embodiments, as an optional embodiment, the electrocardiogram (ECG) images of each lead region are refined using the eight-neighborhood sparse outlier removal algorithm and a pre-stored refinement algorithm to obtain the ECG waveform curves of each lead region, including:
[0114] For any lead region's electrocardiogram image, based on the eight-neighborhood sparse outlier removal algorithm, noise pixels in the electrocardiogram image of that lead region are removed;
[0115] Understandably, although Gaussian filtering was used to filter out noise pixels during the preprocessing stage, some relatively isolated pixels still exist in the electrocardiogram image. These isolated pixels are likely noise. Therefore, this invention uses an eight-neighborhood sparse outlier removal algorithm to remove isolated pixels (noise pixels) and reduce the impact of isolated pixels on the extraction of effective pixels.
[0116] Using a pre-stored thinning algorithm, the electrocardiogram image after removing noise pixels is thinned to obtain the electrocardiogram waveform curve of any one of the lead regions.
[0117] The purpose of the refinement operation is to ensure that the final electrocardiogram waveform curve is composed of single pixels, that is, the pixels on the horizontal axis correspond one-to-one with the pixels on the vertical axis.
[0118] This invention accurately extracts the pixel information of the electrocardiogram (ECG) curve in each lead region by removing noisy pixels and maintaining the ECG waveform curve as a single pixel, thereby generating the ECG curve for each lead region.
[0119] Based on the above embodiments, as an optional embodiment, the removal of noisy pixels in the electrocardiogram of any lead region based on the eight-neighborhood sparse outlier removal algorithm includes:
[0120] The foreground pixels of the electrocardiogram traversing any one of the lead regions along the vertical scan line;
[0121] Foreground pixels that meet the first set condition are identified as noise pixels.
[0122] Remove the noisy pixels;
[0123] The first setting condition is that the number of foreground pixels contained in the eight-neighbor area is less than a preset threshold.
[0124] Specifically, for the binary grayscale image of each lead region, the ECG curve pixels and noise pixels are regarded as foreground pixels with a pixel value of 0 (black); the pixels corresponding to the paper are background pixels with a pixel value of 255 (white).
[0125] To filter out noise pixels in the foreground pixels, this invention separates isolated pixels based on eight-neighbor sparsity and filters out the separated isolated pixels as noise pixels.
[0126] The process for separating isolated pixels based on the sparsity of eight neighborhoods is as follows: traverse the pixels along the vertical scan line; if the number of foreground pixels contained in the eight neighborhood of the traversed foreground pixel is less than 3, then the traversed foreground pixel is considered an isolated pixel; otherwise, the traversed foreground pixel is considered an ECG curve pixel; repeat this process until the scan is completed.
[0127] Here, the method for filtering out noise pixels is to set the pixel value of the noise pixel to be consistent with the pixel value (255) of the background pixel, so that the noise pixel is filtered out as background.
[0128] The eight-neighbor range of a foreground pixel refers to the range covered by its eight adjacent pixels, four of which are horizontal and vertical neighbors, and the other four are diagonal neighbors.
[0129] Figure 4 The example shows a magnified schematic diagram of the ECG waveform curve in the lead area. It is clear that the noise pixels in the figure are relatively isolated, the foreground pixels (pixel value of 0) in their eight-neighbor range are relatively sparse, and the diagonal neighbors are mostly background pixels (pixel value of 255).
[0130] Based on the characteristic that foreground pixels are relatively sparse within the eight-neighbor range of noise pixels, this invention further identifies and removes noise pixels in the electrocardiogram of each lead region, laying the foundation for the accurate extraction of pixel information of the electrocardiogram curve in each lead region.
[0131] Based on the above embodiments, as an optional embodiment, the step of using a pre-stored thinning algorithm to thin the electrocardiogram image after removing noise pixels to obtain the electrocardiogram waveform curve of any one lead region includes:
[0132] An array is used to represent the foreground pixels contained in the electrocardiogram image after removing noise pixels;
[0133] The array of foreground pixels is traversed in ascending order of their horizontal coordinates, and the vertical coordinate of the foreground pixel that has a unique correspondence with the horizontal coordinate of each traversed foreground pixel is determined.
[0134] Add the coordinate pairs consisting of the x-coordinate and y-coordinate of the foreground pixel that have a unique correspondence to the foreground pixel list to generate a refined foreground pixel list.
[0135] Pixel fitting is performed on the refined foreground pixel list to obtain the electrocardiogram waveform curve of any one of the lead regions;
[0136] The foreground pixel list is initially empty, and the value of each foreground pixel in the array is its position coordinate in the electrocardiogram after the removal of noise pixels.
[0137] Specifically, the ECG waveform pixels in the ECG image after the aforementioned processing are represented by an array A of size (N,2), where N is the number of ECG waveform pixels, and the value of each ECG waveform pixel corresponds to its (x,y) coordinates.
[0138] Arrange the ECG waveform pixels in array A sequentially along the x-direction, and then traverse them from left to right.
[0139] Set an empty list B;
[0140] During the traversal, determine the y value that has a unique correspondence with each x value, and fill the resulting (x, y) into list B as the refined ECG waveform pixels;
[0141] After traversal, the N refined ECG waveform pixels in list B are fitted to obtain the final ECG waveform curve data.
[0142] The fitting method may include, but is not limited to, second-order spline interpolation.
[0143] This invention iterates through the pixel coordinates in the array along the x-axis and finds the y that uniquely corresponds to each x, thereby making the ECG waveform curve obtained by fitting each (x, y) uniquely determined.
[0144] Based on the above embodiments, as an optional embodiment, determining the ordinate of the foreground pixel that has a unique correspondence with the abscissa of each traversed foreground pixel includes:
[0145] When the x-coordinate of the foreground pixel point being traversed has only one corresponding y-coordinate in the array, it is determined that there is a unique correspondence between the unique y-coordinate of the foreground pixel point and the x-coordinate of the foreground pixel point being traversed.
[0146] When the x-coordinate of the foreground pixel point being traversed has multiple corresponding y-coordinates in the array, it is determined whether the maximum distance difference between the multiple y-coordinates of the foreground pixel points is not greater than a first preset distance difference, and based on the determination result, the y-coordinate of the foreground pixel point that has a unique correspondence with the x-coordinate of the foreground pixel point being traversed is determined.
[0147] In other words, this invention measures the density of the multiple foreground pixels by the maximum distance difference between their ordinates, and uses this density as the criterion for determining the ordinate of the foreground pixel that has a unique correspondence with the abscissa of the traversed foreground pixels, thus ensuring the accuracy of digitization.
[0148] Based on the above embodiments, as an optional embodiment, determining the ordinate of the foreground pixel that has a unique correspondence with the abscissa of the traversed foreground pixel based on the judgment result includes:
[0149] If the judgment result is yes, calculate the average value of the ordinates of the multiple foreground pixels;
[0150] It is determined that there is a unique correspondence between the average value and the x-coordinate of the foreground pixel point being traversed.
[0151] In other words, this invention determines that when the maximum distance difference between the ordinates of the plurality of foreground pixels is less than a first preset distance difference, it means that the ordinates of the plurality of foreground pixels are very close to each other. Therefore, the average value of the ordinates of the plurality of foreground pixels is used as the ordinate of the foreground pixel that has a unique correspondence with the x-coordinate of the traversed foreground pixels. This ensures the accuracy of the digitization.
[0152] Based on the above embodiments, as an optional embodiment, the step of determining the ordinate of the foreground pixel that has a unique correspondence with the abscissa of the traversed foreground pixel based on the judgment result further includes:
[0153] If the judgment result is negative, obtain the ordinate of the foreground pixel that has a unique correspondence with the foreground pixel whose x-coordinate is one before the foreground pixel in the traversal order.
[0154] Calculate the difference between the ordinate of each of the plurality of foreground pixels and the obtained ordinate of the foreground pixels;
[0155] The ordinates of the foreground pixels whose differences are within a preset range are assigned to a first list, and the ordinates of the foreground pixels whose differences are not within a preset range are assigned to a second list.
[0156] If the number of foreground pixels in the second list is greater than the preset number, it is determined that there is a unique correspondence between the ordinate of the foreground pixel with the largest difference in the second list and the abscissa of the traversed foreground pixels.
[0157] If the number of foreground pixels in the second list is not greater than a preset number, it is determined that there is a unique correspondence between the average value of the ordinate of the foreground pixels in the first list and the x-coordinate of the traversed foreground pixels.
[0158] This invention determines that when the maximum distance difference between the ordinates of the multiple foreground pixels is not less than a first preset distance difference, there is a certain probability that a pixel peak will occur. Therefore, it introduces a foreground pixel ordinate that has a unique correspondence with the foreground pixel ordinate that precedes the traversed foreground pixel ordinate in the traversal order. Furthermore, it designs certain rules to determine the foreground pixel ordinate that has a unique correspondence with the traversed foreground pixel ordinate. This ensures the accuracy of the digitization.
[0159] In general, the process of determining the y value that has a unique correspondence with each x value can be achieved through the following steps;
[0160] For each x value, if there is only one y value in array A corresponding to it, then the y value and x value are considered to have a unique correspondence.
[0161] If there are multiple y values in array A corresponding to it, then determine the difference between the maximum and minimum values among the multiple y values and a certain threshold, where the threshold is set to 10.
[0162] If the distance difference is less than or equal to 10, then the average of these multiple y values, y_mean, is considered to have a unique correspondence with the x value.
[0163] If the distance difference is greater than 10, calculate the difference between each of these y values and the y value y_pre that has a unique correspondence with the previous x value, and store the y values with a difference within plus or minus 5 in the list low_vals, and store the y values with a difference outside plus or minus 5 in the list high_vals.
[0164] If the number of y values in high_vals is greater than 5, the x value is considered to correspond to the peak point of the electrocardiogram curve. In this case, the y value with the largest difference from y_pre in high_vals is considered to have a unique correspondence with the x value. If the number of y values in high_vals is no greater than 5, the average value of y values in low_vals is considered to have a unique correspondence with the x value.
[0165] This invention designs an algorithm to determine a unique y for each x, while ensuring that the determined y is as close to reality as possible.
[0166] Based on the above embodiments, as an optional embodiment, the step of connecting the ECG waveform curves of each lead region along the lead dimension to obtain the digital result of the paper ECG includes:
[0167] The electrocardiogram waveforms of each lead region were sequentially normalized and clipped to the same length.
[0168] The ECG waveform curves of each lead region after normalization and equal-length cropping are connected to obtain the digital result of the paper ECG.
[0169] The ECG waveform curves for each lead region are normalized using the following formula:
[0170] xl ,i =xori ,l,i -min(xori ,l,0 ,xori ,l,1 ,……xori ,l,n-1 ,xori ,l,n )
[0171] In the formula, l corresponds to the lead number, n corresponds to the number of pixels contained in the ECG waveform curve of lead region l, and xl ,i xori is the pixel value of the i-th pixel in the ECG waveform curve of the l-th lead region after normalization. ,l,i is the pixel value of the i-th pixel in the electrocardiogram waveform curve of the l-th lead region;
[0172] That is, for each lead, the value of each pixel in the ECG waveform curve is subtracted from the value of the smallest pixel to obtain the relative change value of the pixel coordinates, and the ECG waveform is characterized by the relative change value of the pixel coordinates.
[0173] Equal-length trimming means standardizing the ECG waveform curves of all lead regions to the same length. The specific standardization method is as follows:
[0174] Set the length parameter max_length. For the ECG waveform curve of each lead region, if the length is less than max_length, repeat the curve segment until it is filled to a sufficient length. If the length is greater than max_length, directly take the curve segment with the first max_length length.
[0175] This invention provides a convenient way to splice the ECG waveform curves of twelve lead regions through normalization and equal-length trimming.
[0176] It should be noted that the present invention can also merge the ECG waveform curves of the twelve lead regions to generate a two-dimensional array of size (12, max_length).
[0177] Figure 5 This example demonstrates the digital results of a paper electrocardiogram for acute aortic dissection type A at Stanford University. Figure 6 The digital results of paper electrocardiograms for ST-segment elevation myocardial infarction are shown in the example. Manual analysis revealed that the digitalization effect of this invention is very good.
[0178] Currently, many cardiac diseases are difficult to differentiate manually in clinical practice, urgently requiring the intervention of automated analysis technology. For example, ST-segment elevation myocardial infarction (STEMI) and Stanford type A acute aortic dissection (Stanford type A AAD) are two of the most important differential diagnoses in the initial presentation of acute chest pain. Both STEMI and Stanford type A AAD can present with acute, severe chest pain, and both are emergencies requiring rapid diagnosis and treatment. When ST-segment elevation is found on the initial electrocardiogram, Stanford type A AAD is often misdiagnosed as STEMI. Alarmingly, the core treatments based on the pathological mechanisms of STEMI are completely contraindicated for Stanford type A AAD; antiplatelet, antithrombin, and thrombolytic drug treatments can lead to catastrophic bleeding, accelerating its progression and rupture, and promoting patient death. Clearly, rapid differentiation between STEMI and Stanford type A AAD within a limited timeframe has significant clinical importance.
[0179] To address the clinical need for rapid differentiation between Stanford type A AAD and STEMI, this invention constructs an interpretation model for Stanford type A AAD and STEMI based on the digitization of paper electrocardiograms.
[0180] Specifically, the sample set consists of the pixel information of the electrocardiogram waveform obtained by digitizing the Stanford Type A AAD paper electrocardiogram (i.e., a two-dimensional array representing the electrocardiogram curve values of the twelve lead regions of the Stanford Type A AAD) and its corresponding Stanford Type A AAD label, and the pixel information of the electrocardiogram waveform obtained by digitizing the STEMI paper electrocardiogram (i.e., a two-dimensional array representing the electrocardiogram curve values of the twelve lead regions of the STEMI) and its corresponding STEMI label.
[0181] The sample set is divided into a training set and a validation set; the ratio of the division can be, but is not limited to, 8:2.
[0182] Based on the pre-trained weighted initialization model, a judgment model is constructed using the training and validation sets. This model takes a two-dimensional array representing the ECG curve values of twelve lead regions as input and outputs the disease type (Stanford type A AAD or STEMI). During training, validation is performed continuously, and the best-performing model on the validation set is selected as the judgment model.
[0183] The pre-trained weight initialization model was obtained by training the classification network architecture using the CPSC open-source ECG dataset. Specifically, the relatively optimal model weights were obtained through iterative training. Essentially, this involved continuously adjusting the weights in the network using a loss function. At each epoch, the average classification accuracy was calculated using the validation set, and the weights with the best classification accuracy were used as the final pre-trained weights to initialize the model. The classification network architecture included, but was not limited to, the ResNet34 classification model.
[0184] It can be said that, based on the pre-trained weights obtained from the CPSC open-source ECG dataset, the interpretation models for both types of data were obtained by fine-tuning the weights using Stanford type A AAD and STEMI data.
[0185] Figure 7 The example shows the training loss change curve of the interpretation model. Figure 8 The example shows the curve of the interpretation accuracy variation of the interpretation model.
[0186] In summary, to address the clinical need for rapid differentiation between Stanford type A AAD and STEMI, and considering the current lack of relevant open-source datasets, this invention constructs a model for interpreting Stanford type A AAD and STEMI. This model utilizes the digitized results of paper electrocardiograms to represent the pixel information of the ECG waveform. It is trained using pixel information from both types of ECG waveforms and their disease type labels to differentiate between Stanford type A AAD and STEMI, laying the foundation for specific clinical interpretation needs that are difficult to achieve manually.
[0187] Secondly, the paper electrocardiogram digitization device provided by the present invention will be described, and the paper electrocardiogram digitization device described below and the paper electrocardiogram digitization method described above can be referred to in correspondence with each other. Figure 9 An example is a schematic diagram of a paper-based electrocardiogram (ECG) digitization device, the device comprising:
[0188] Preprocessing module 21 is used to preprocess the electronic image of a paper electrocardiogram containing twelve lead regions to obtain an electrocardiogram image;
[0189] Separation module 22 is used to separate the various lead regions of the electrocardiogram;
[0190] The thinning processing module 23 is used to thin the electrocardiogram images of each lead region based on the eight-neighbor sparse outlier removal algorithm and the pre-stored thinning algorithm to obtain the electrocardiogram waveform curves of each lead region.
[0191] Connection module 24 is used to connect the electrocardiogram waveform curves of each lead region along the lead dimension to obtain the digital result of the paper electrocardiogram.
[0192] This invention provides a device for digitizing paper electrocardiograms (ECGs). It preprocesses and separates the electronic images of a paper ECG containing twelve lead regions, extracting the corresponding ECG curve pixels for each lead region. Then, it refines the ECG curve pixels for each lead region to obtain the ECG curve for each lead region. Finally, it connects the ECG curves of each lead region along the lead dimension to obtain the ECG waveform curves of the twelve leads. By digitizing the effective ECG signal information from the paper ECG, the continuously generated paper ECGs from hospitals can be converted into electronic ECGs, solving the problem of insufficient electronic ECG volume leading to difficulties in implementing automatic ECG abnormality analysis and promoting the development of the field of automatic ECG analysis.
[0193] The paper electrocardiogram digitization device provided in this embodiment of the invention specifically executes the processes of the above-described paper electrocardiogram digitization method embodiments. For details, please refer to the contents of the above-described paper electrocardiogram digitization method embodiments, which will not be repeated here.
[0194] Thirdly, Figure 10 An example is a schematic diagram of the physical structure of an electronic device. For example... Figure 10 As shown, the electronic device may include a processor 1010, a communications interface 1020, a memory 1030, and a communication bus 1040, wherein the processor 1010, the communications interface 1020, and the memory 1030 communicate with each other via the communication bus 1040. The processor 1010 can call logical instructions in the memory 1030 to execute a paper electrocardiogram digitization method. This method includes: preprocessing an electronic image of a paper electrocardiogram containing twelve lead regions to obtain an electrocardiogram image; separating each lead region of the electrocardiogram image; refining the electrocardiogram image of each lead region based on an eight-neighborhood sparse outlier removal algorithm and a pre-stored refinement algorithm to obtain the electrocardiogram waveform curve of each lead region; and connecting the electrocardiogram waveform curves of each lead region along the lead dimension to obtain the digitization result of the paper electrocardiogram.
[0195] Furthermore, the logical instructions in the aforementioned memory 1030 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0196] Fourthly, the present invention also provides a computer program product, the computer program product comprising a computer program that can be stored on a non-transitory computer-readable storage medium, wherein when the computer program is executed by a processor, it performs a method for digitizing a paper electrocardiogram, the method comprising: preprocessing an electronic image of a paper electrocardiogram containing twelve lead regions to obtain an electrocardiogram image; separating each lead region of the electrocardiogram image; refining the electrocardiogram image of each lead region based on an eight-neighborhood sparse outlier removal algorithm and a pre-stored refining algorithm to obtain an electrocardiogram waveform curve of each lead region; and connecting the electrocardiogram waveform curves of each lead region along the lead dimension to obtain the digitization result of the paper electrocardiogram.
[0197] Fifthly, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon for executing a method for digitizing a paper electrocardiogram (ECG). The method includes: preprocessing an electronic image of a paper ECG containing twelve lead regions to obtain an ECG image; separating each lead region of the ECG image; refining the ECG image of each lead region based on an eight-neighborhood sparse outlier removal algorithm and a pre-stored refining algorithm to obtain ECG waveform curves of each lead region; and connecting the ECG waveform curves of each lead region along the lead dimension to obtain the digitized result of the paper ECG.
[0198] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0199] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0200] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for digitizing paper electrocardiograms, characterized in that, The method includes: The electronic image of the paper electrocardiogram containing twelve lead regions is preprocessed to obtain the electrocardiogram image; Separate the individual lead regions of the electrocardiogram; For an electrocardiogram (ECG) image of any lead region, based on an eight-neighborhood sparse outlier removal algorithm, noisy pixels in the ECG image of that lead region are removed, including: Traverse the foreground pixels along the vertical scan line, and identify and remove foreground pixels whose number of foreground pixels in the eight-neighbor range is less than a preset threshold as noise pixels. Using a pre-stored thinning algorithm, the electrocardiogram (ECG) image after removing noise pixels is thinned to obtain the ECG waveform curve of any one lead region, including: For each horizontal coordinate in the electrocardiogram, a unique vertical coordinate value is determined; when multiple foreground pixels have corresponding vertical coordinates for a horizontal coordinate, it is first determined whether the maximum distance difference between the multiple vertical coordinates is greater than a first preset distance difference: If not, the average of the multiple ordinates is calculated as the unique ordinate value; If so, obtain the determined ordinate value corresponding to the previous x-coordinate, and divide the multiple ordinates into a first list with differences within a preset range and a second list with differences outside the preset range based on the differences between the multiple ordinates and the previous ordinate value. Determine whether the number of vertical coordinates in the second list is greater than a preset number; If the number of ordinates in the second list is greater than the preset number, then the ordinate with the largest difference from the previous ordinate value in the second list is identified as the unique ordinate value of the x-axis. If the number of ordinates in the second list is not greater than the preset number, then the average value of the ordinates in the first list is calculated as the unique ordinate value of the horizontal axis. The electrocardiogram waveforms of each lead region are connected along the lead dimension to obtain the digital result of the paper electrocardiogram.
2. The method for digitizing paper electrocardiograms according to claim 1, characterized in that, The preprocessing includes at least: noise pixel removal, stamp removal, and background grid line removal.
3. The method for digitizing paper electrocardiograms according to claim 2, characterized in that, The electronic image of the paper electrocardiogram is preprocessed to obtain an electrocardiogram image, including: Gaussian filtering is used to remove noise pixels from the electronic image; Based on RGB channel separation technology, the grayscale image of the electronic image after filtering out noise pixels is obtained in the R channel; Perform foreground-background separation on the grayscale image to obtain a binarized grayscale image with the stamp removed; The positions of the background grid lines are obtained by processing the grayscale image corresponding to the electronic image using binary morphological operations. Based on the location of the background grid lines, the background grid lines in the binarized grayscale image are removed to obtain the electrocardiogram image.
4. The method for digitizing paper electrocardiograms according to claim 1, characterized in that, The separation of the various lead regions of the electrocardiogram includes: The locations of each lead region in the electrocardiogram are marked manually. Based on the location markers, the separation of each lead region in the electrocardiogram is achieved.
5. The method for digitizing paper electrocardiograms according to claim 1, characterized in that, The algorithm for removing sparse outliers based on eight neighborhoods, which removes noisy pixels from the electrocardiogram of any lead region, specifically includes: The foreground pixels of the electrocardiogram traversing any one of the lead regions along the vertical scan line; Foreground pixels that meet the first set condition are identified as noise pixels. Remove the noisy pixels; The first setting condition is that the number of foreground pixels contained in the eight-neighbor area is less than a preset threshold.
6. The method for digitizing paper electrocardiograms according to claim 4, characterized in that, The step of connecting the electrocardiogram waveform curves of each lead region along the lead dimension to obtain the digital result of the paper electrocardiogram includes: The electrocardiogram waveforms of each lead region were sequentially normalized and clipped to the same length. The ECG waveform curves of each lead region after normalization and equal-length cropping are connected to obtain the digital result of the paper ECG.
7. A paper-based electrocardiogram (ECG) digitization device, characterized in that, The device includes: The preprocessing module is used to preprocess the electronic image of a paper electrocardiogram containing twelve lead regions to obtain an electrocardiogram image; A separation module is used to separate the various lead regions of the electrocardiogram; The refinement module is used to remove noisy pixels from the electrocardiogram (ECG) image of any lead region based on an eight-neighborhood sparse outlier removal algorithm, including: Traverse the foreground pixels along the vertical scan line, and identify and remove foreground pixels whose number of foreground pixels in the eight-neighbor range is less than a preset threshold as noise pixels. Using a pre-stored thinning algorithm, the electrocardiogram (ECG) image after removing noise pixels is thinned to obtain the ECG waveform curve of any one lead region, including: For each horizontal coordinate in the electrocardiogram, a unique vertical coordinate value is determined; when multiple foreground pixels have corresponding vertical coordinates for a horizontal coordinate, it is first determined whether the maximum distance difference between the multiple vertical coordinates is greater than a first preset distance difference: If not, the average of the multiple ordinates is calculated as the unique ordinate value; If so, obtain the determined ordinate value corresponding to the previous x-coordinate, and divide the multiple ordinates into a first list with differences within a preset range and a second list with differences outside the preset range based on the differences between the multiple ordinates and the previous ordinate value. Determine whether the number of vertical coordinates in the second list is greater than a preset number; If the number of ordinates in the second list is greater than the preset number, then the ordinate with the largest difference from the previous ordinate value in the second list is identified as the unique ordinate value of the x-axis. If the number of ordinates in the second list is not greater than the preset number, then the average value of the ordinates in the first list is calculated as the unique ordinate value of the horizontal axis. The connection module is used to connect the electrocardiogram waveform curves of each lead region along the lead dimension to obtain the digital result of the paper electrocardiogram.