A method for drawing electrocardiogram superimposition diagram based on pixel weight statistics
Patent Information
- Application Number
- CN202611149690.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-31
- Publication Date
- 2026-08-28
AI Technical Summary
[0002]在动态心电分析软件中,医生常通过叠加图观察大量心搏波形的一致性、异常形态及模板分类结果,传统方式通常将多个心搏波形逐条绘制到显示区域中,例如使用CPU图形接口逐条调用绘图函数,当心搏数量较多、记录时间较长或需要频繁刷新叠加图时,该方式计算量大、绘制耗时长,容易造成界面卡顿
[0046] 1. By dividing the set of heartbeats to be drawn into multiple groups according to their quantity, and processing each group by a CPU worker thread, the cumulative number of times the heartbeat waveform passes through pixels is counted in parallel by CPU multi-threading, which helps to improve the generation speed of a large number of heartbeat overlay images. At the same time, each thread uses an independent pixel weight buffer to avoid lock contention when multiple threads write to the same image buffer. It does not depend on GPU, OpenCL or specific graphics card drivers and can run on older systems such as Windows XP.
Smart Images

Figure CN122654737A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of electrocardiogram (ECG) rendering technology, specifically a method for rendering ECG overlays based on pixel weight statistics. Background Technology
[0002] In dynamic electrocardiogram analysis software, doctors often observe the consistency, abnormal morphology and template classification results of a large number of heartbeat waveforms through overlay graphs. The traditional method usually draws multiple heartbeat waveforms one by one into the display area, such as calling the drawing function one by one using the CPU graphics interface. When there are many heartbeats, the recording time is long, or the overlay graph needs to be refreshed frequently, this method has a large amount of calculation and long drawing time, which can easily cause the interface to lag.
[0003] To improve rendering speed, existing solutions can use parallel computing methods such as GPU or OpenCL to offload waveform point statistics or rendering tasks to the graphics card. This method has a good speed advantage in environments that support OpenCL / GPU, but it depends on the graphics card hardware, drivers and operating environment. On Windows XP or some older devices, OpenCL support is insufficient, which makes the GPU acceleration solution unstable. It is still necessary to use the CPU graphics interface to call the drawing functions one by one, resulting in a long rendering time and easy interface lag. Summary of the Invention
[0004] The purpose of this invention is to provide a method for drawing electrocardiogram overlays based on pixel weight statistics, so as to solve the problems mentioned in the background art.
[0005] To achieve the above objectives, the present invention provides the following technical solution:
[0006] A method for drawing an electrocardiogram overlay based on pixel weight statistics includes:
[0007] Obtain the set of heartbeats for the overlay image to be drawn, and extract the R-point position or alignment reference point corresponding to each heartbeat;
[0008] Obtain the display parameters of the overlay image, and use the display parameters to establish the mapping relationship between sampling points and pixel coordinates;
[0009] The heartbeat set to be drawn is divided into multiple groups according to the number of heartbeats. Each group is processed by a CPU worker thread, and an independent pixel weight buffer is allocated to each worker thread.
[0010] In the pixel weight buffer, each working thread converts the corresponding heartbeat waveform point into image pixel coordinates according to the mapping relationship;
[0011] Merge the pixel weight buffers of each thread to obtain the global pixel weight buffer;
[0012] A density color image is generated based on pixel weights, forming an overlay image which is then displayed.
[0013] Furthermore, after extracting the alignment reference points corresponding to the heartbeats, the alignment reference points of each heartbeat are corrected according to the preset alignment method.
[0014] Alignment methods should include at least:
[0015] Align with point R;
[0016] Vertical alignment is performed using the voltage at point R;
[0017] Search for the highest voltage point within a preset range near point R, and align with the highest voltage point;
[0018] Search for the lowest voltage point within a preset range near point R, and align with the lowest point;
[0019] Based on the main orientation of the R wave in the heartbeat set, the highest or lowest point is automatically selected for alignment.
[0020] Furthermore, the overlay display parameters include at least the display area width, display area height, display gain, display duration, alignment method, and reverse display parameters.
[0021] Furthermore, establishing the mapping relationship between sampling points and pixel coordinates includes:
[0022] The sampling rate conversion factor is determined based on the ratio of the actual sampling rate to the reference sampling rate, and the horizontal sampling multiple is determined based on the sampling rate conversion factor and the display duration multiple.
[0023] Determine the number of sampling points to be read based on the display area width, the horizontal sampling multiple, and the standard horizontal multiple;
[0024] The number of sampling points is obtained based on the parameter of the correspondence between sampling points and pixels and the width of the display area, and the display duration is calculated based on the sampling rate.
[0025] Determine the starting point for reading; the starting point can be one-quarter, one-half, or three-quarters of the width of the display area.
[0026] A number of sampling points are uniformly mapped onto the width of the horizontal display area;
[0027] The voltage values, vertical alignment reference, display gain, and reverse display parameters of the ECG sampling points are converted into the vertical pixel positions in the overlay image.
[0028] Furthermore, the set of heartbeats to be drawn is divided into multiple groups according to their quantity, including:
[0029] Obtain the number of CPU logical processors, and determine the number of worker threads based on the number of processors;
[0030] When the total number of heartbeats is less than or equal to one thousand, all heartbeats are grouped together.
[0031] When the total number of heartbeats is greater than one thousand, the average number of heartbeats per working thread is calculated based on the total number of heartbeats.
[0032] If the average number of heartbeats is less than one thousand, the heartbeat set is divided into several groups in the original order, with each group containing one thousand heartbeats, and the remaining heartbeats with less than one thousand heartbeats are grouped together.
[0033] If the average number of heartbeats is greater than or equal to one thousand, the heartbeat set is divided into several groups in the original order, and the number of heartbeats in each group is the average number of heartbeats.
[0034] Preferably, after converting the heartbeat waveform points into image pixel coordinates, the midpoint of adjacent sampling points is calculated, and the difference between adjacent sampling points is statistically analyzed.
[0035] Preferably, a pixel weight buffer is selected as the global pixel weight buffer, and the same index elements in the other pixel weight buffers are accumulated one by one into the global pixel weight buffer. After the merging is completed, the private pixel weight buffers of other threads are released.
[0036] Preferably, generating a density color image based on pixel weights includes:
[0037] The average pixel weight is calculated based on the weight distribution of the image column, and the density threshold is calculated based on the average pixel weight and the preset first density coefficient and second density coefficient.
[0038] The average pixel weight is compared with the density threshold, and different pixel density regions are mapped to different colors according to the preset color mapping rules.
[0039] When the number of non-zero pixels in a column is less than the preset number, a reduced density threshold is used to map different pixel density regions to different colors.
[0040] Furthermore, calculating the average pixel weight by image column includes:
[0041] Calculate the total weight Sx of all non-zero pixels in the column, and count the number of non-zero pixels Qx;
[0042] If Qx is greater than 0, the average pixel Ax is equal to the ratio of Sx to Qx;
[0043] When Qx equals 0, it means that no heartbeat waveform passes through this column, and the entire column retains its background color.
[0044] Preferably, in the process of mapping different pixel density regions to different colors, the pixel weight is compared with the density threshold to determine whether it is a region where a heartbeat-free waveform passes through, a low-density region, a medium-density region, or a high-density region. The region where a heartbeat-free waveform passes through is mapped to black, the low-density region to green, the medium-density region to yellow, and the high-density region to red.
[0045] Compared with the prior art, the beneficial effects of the present invention are:
[0046] 1. By dividing the set of heartbeats to be drawn into multiple groups according to their quantity, and processing each group by a CPU worker thread, the cumulative number of times the heartbeat waveform passes through pixels is counted in parallel by CPU multi-threading, which helps to improve the generation speed of a large number of heartbeat overlay images. At the same time, each thread uses an independent pixel weight buffer to avoid lock contention when multiple threads write to the same image buffer. It does not depend on GPU, OpenCL or specific graphics card drivers and can run on older systems such as Windows XP.
[0047] 2. By generating density and color images based on pixel weights, an overlay image is formed and displayed. The overlay image is generated using weight statistics and density mapping, which preserves waveform overlap density information and reduces the overhead of drawing each line individually. Different colors are displayed according to the weight, enabling doctors to intuitively identify high-frequency overlapping areas and abnormal discrete areas. It is suitable for various ECG analysis scenarios such as template overlay, scattered selection of heartbeat overlay, and heartbeat classification auxiliary analysis. Attached Figure Description
[0048] Figure 1 This is an overall flowchart of the method of the present invention;
[0049] Figure 2 This is a schematic diagram of the multi-threaded heart rate grouping processing in this invention;
[0050] Figure 3 This is a flowchart of the single heartbeat waveform processing in this invention;
[0051] Figure 4 This is a superimposed diagram of the results from this invention. Detailed Implementation
[0052] 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 without creative effort are within the scope of protection of the present invention.
[0053] Please see Figure 1-4In this embodiment of the invention, a method for drawing an electrocardiogram overlay based on pixel weight statistics includes:
[0054] S1, obtain the set of heartbeats in the overlay image to be drawn, and extract the R point position or alignment reference point corresponding to each heartbeat;
[0055] S2, obtain the overlay image display parameters, and use the display parameters to establish the mapping relationship between sampling points and pixel coordinates;
[0056] The parameters for displaying overlay images include at least the display area width, display area height, display gain, display duration, alignment method, and reverse display parameters;
[0057] S3, the set of heartbeats to be drawn is divided into multiple groups according to the number of beats, each group is processed by a CPU worker thread, and an independent pixel weight buffer is allocated to each worker thread;
[0058] S4, In the pixel weight buffer, each working thread converts the corresponding heartbeat waveform point into image pixel coordinates according to the mapping relationship;
[0059] S5, merge the pixel weight buffers of each thread to obtain the global pixel weight buffer;
[0060] S6 generates a density color image based on pixel weights, forms an overlay image, and displays it.
[0061] Specifically, by dividing the set of heartbeats to be drawn into multiple groups according to their quantity, each group is processed by a CPU worker thread. The cumulative number of times the heartbeat waveform passes through pixels is counted in parallel by CPU multi-threading, which helps to improve the generation speed of a large number of heartbeat overlay images. Furthermore, by generating density color images based on pixel weights, an overlay image is formed and displayed. The overlay image is generated using weight statistics and density mapping, which not only preserves the waveform overlap density information but also reduces the overhead of drawing each line. This achieves relatively smooth operation on older systems such as Windows XP without relying on GPU, OpenCL, or specific graphics card drivers, and only using CPU multi-threaded parallel processing, which helps to improve the doctor's operating experience.
[0062] Meanwhile, each thread uses an independent pixel weight buffer, avoiding lock contention when multiple threads write to the same image buffer, which helps ensure efficiency and stability; and different colors are displayed according to the weight, enabling doctors to intuitively identify high-frequency overlapping areas and abnormal discrete areas, which is suitable for various ECG analysis scenarios such as template overlay, scattered point selection of heartbeat overlay, and heartbeat classification auxiliary analysis.
[0063] like Figure 1 As shown, in this embodiment, after extracting the alignment reference point corresponding to the heartbeat in S1, the alignment reference point of each heartbeat is corrected according to the preset alignment method.
[0064] Alignment methods should include at least:
[0065] Align with point R;
[0066] Vertical alignment is performed using the voltage at point R;
[0067] Search for the highest voltage point within a preset range near point R, and align with the highest voltage point;
[0068] Search for the lowest voltage point within a preset range near point R, and align with the lowest point;
[0069] Based on the main orientation of the R wave in the heartbeat set, the highest or lowest point is automatically selected for alignment.
[0070] In practice, under the automatic alignment mode that automatically selects the highest or lowest point for alignment, the system counts the highest and lowest voltages of multiple heartbeats within the range near the R point. When the positive R wave is in the majority, the highest point is selected for alignment, and when the negative R wave is in the majority, the lowest point is selected for alignment.
[0071] like Figure 1 As shown, in this embodiment, the width of the overlay display area is W, the height of the display area is H, the horizontal display multiplier is M, the alignment reference point of the current heartbeat is R, the ECG data sampling rate is F, the reference sampling rate is F0, and the display duration multiplier is D.
[0072] The mapping relationship between sampling points and pixel coordinates in S2 includes:
[0073] S21, determine the sampling rate conversion factor based on the ratio of the actual sampling rate to the reference sampling rate, and determine the horizontal sampling multiple based on the sampling rate conversion factor and the display duration multiple;
[0074] In practice, the system uses 256Hz as the baseline sampling rate.
[0075] When the sampling rate is no greater than 256Hz, the sampling rate conversion factor Q is taken as 1.
[0076] When the sampling rate is greater than 256Hz, the ratio of the actual sampling rate to the reference sampling rate is rounded up to obtain the sampling rate conversion factor:
[0077] Q = max(1, ceil(F / F0));
[0078] Where ceil represents rounding up, and Q represents the sampling rate conversion factor determined based on the actual sampling rate.
[0079] The display duration multiplier D controls how long the ECG waveform is displayed within the same image width, for example:
[0080] D=0.5 means that the display duration is 0.5 times the base duration;
[0081] D=1 indicates the display base duration;
[0082] D=2 indicates that the display duration is twice the base duration;
[0083] D=3 indicates that the display duration is 3 times the baseline duration;
[0084] In one parameter setting method of the present invention, the standard lateral multiple M0 is set to 4, therefore the lateral sampling multiple is:
[0085] M = 4 × D × Q;
[0086] The standard horizontal multiplier of 4 is the baseline value for the horizontal parameter, and its function is to keep the scale consistent in subsequent coordinate conversions.
[0087] When D=1 and Q=1, the value of M is 4, which means that under the reference sampling rate and standard display duration, one sampling point corresponds to one horizontal pixel.
[0088] S22, determine the number of sampling points to be read based on the display area width, horizontal sampling multiple, and standard horizontal multiple;
[0089] In practice, the image width is W. Under standard conditions, M=4, and W sampling points need to be read so that they correspond to W horizontal pixels respectively.
[0090] When M changes, the number of read points changes proportionally to M / 4. Therefore, the actual number of read points = image width × current horizontal multiple ÷ standard horizontal multiple, which is:
[0091] L = W × M / 4;
[0092] Where L is the number of sampling points involved in the superimposed display of a heartbeat, and the constant 4 is the standard horizontal multiple.
[0093] For example, the image width is 800 pixels:
[0094] When M=4, L=800×4 / 4=800, the number of sampling points is 800, and one sampling point corresponds to one pixel;
[0095] When M=8, L=800×8 / 4=1600, the number of sampling points is 1600, and two sampling points are compressed to one pixel width;
[0096] When M=2, L=800×2 / 4=400, the number of sampling points is 400, and one sampling point is extended to two pixel widths.
[0097] S23, obtain the number of sampling points based on the parameter of the correspondence between sampling points and pixels and the width of the display area, and then calculate the display duration based on the sampling rate;
[0098] In practice, the sampling rate conversion level is determined based on the ratio of the actual sampling rate to the benchmark sampling rate, and the horizontal sampling multiple is adjusted according to the conversion level. When the actual sampling rate is an integer multiple of the benchmark sampling rate, the display duration under different sampling rates remains consistent; when the actual sampling rate is not an integer multiple of the benchmark sampling rate, the display time range under different sampling rates remains approximately consistent.
[0099] For example, if the image width is 256 pixels, the display duration multiplier D = 1;
[0100] When the sampling rate is 256Hz:
[0101] Q=1, M=4, then L=256×4 / 4=256;
[0102] Display duration = 256 / 256 = 1 second;
[0103] When the sampling rate is 512Hz:
[0104] Q=2, M=8, then L=256×8 / 4=512;
[0105] Display duration = 512 / 512 = 1 second.
[0106] S24, Determine the starting point of the reading. The starting point of the reading is one-quarter, one-half, or three-quarters of the width of the display area.
[0107] In practice, let Ri be the alignment reference point of the i-th heartbeat and Bi be the starting point for reading the i-th heartbeat.
[0108] By default, the alignment reference point Ri needs to be displayed in the center of the horizontal direction of the image, at half the width of the display area. A total of L sampling points are read for one heartbeat. Therefore, half of the data is read before the alignment reference point and the other half is read after the alignment reference point.
[0109] The starting point for reading is:
[0110] Bi = Ri - L / 2;
[0111] Substituting L=W×M / 4 into the above formula, we finally get: Bi=Ri-W×M / 8;
[0112] The alignment reference point is mapped to: x = W / 2, where x is the horizontal pixel coordinate;
[0113] In addition, the alignment reference point can be displayed at one-quarter or three-quarters of the width of the display area;
[0114] When the alignment reference point is located at one-quarter of the width of the display area, one-quarter of the total length is read in front of it:
[0115] Bi = Ri - L / 4;
[0116] Substituting L=W×M / 4 into the above formula, we finally get: Bi=Ri-W×M / 16;
[0117] Alignment reference point mapping to: x = W / 4;
[0118] When the alignment reference point is located at three-quarters of the display area width, three-quarters of the total length is read in front of it:
[0119] Bi = Ri - 3L / 4;
[0120] Substituting L=W×M / 4 into the above formula, we finally get: Bi=Ri-3×W×M / 16;
[0121] Alignment reference point mapping to: x=3W / 4.
[0122] S25, uniformly maps several sampling points across the width of the horizontal display area;
[0123] In practice, let p be the index of the current sampling point relative to the starting point of the reading, and let the value range be 0 ≤ p < L;
[0124] The L sampling points need to be uniformly mapped to W horizontal pixels, where the position of the horizontal pixel is the product of the relative proportion of the current sampling point in the display sampling range and the image width.
[0125] The general mapping formula is: x = floor(p × W / L);
[0126] Substituting L=W×M / 4 into the above formula, we finally get: x=floor(4p / M);
[0127] S26 converts the voltage value, vertical alignment reference, display gain, and reverse display parameters of the ECG sampling point into the vertical pixel position in the overlay image.
[0128] In practice, let the current sampling point voltage be Vip, the longitudinal alignment reference voltage be Vri, and the display gain be G;
[0129] When using vertical alignment: ΔVip = Vip - Vri;
[0130] When longitudinal voltage alignment is not used: Vri=0, then ΔVip=Vip;
[0131] Determine whether to invert the display based on the reverse display parameters, and calculate the display voltage:
[0132] When not inverted: Vaip = ΔVip × G;
[0133] When inverted: Vaip = -ΔVip × G;
[0134] If the quantization range of the reference voltage is V0, then the vertical pixel offset is: dy = Vaip / V0 × H;
[0135] In this embodiment, V0 is determined based on the voltage quantization specifications, voltage calibration relationship, and display amplitude range of the overlay graph of the electrocardiogram data. In this embodiment, V0 = 2048, and 2048 is used as the reference voltage quantization conversion benchmark.
[0136] Let the vertical reference position of the image be yc;
[0137] When the waveform is displayed with the vertical center of the image as the reference: yc=floor(H / 2);
[0138] Since the image coordinates increase downwards, while the positive ECG voltage should be displayed upwards, the vertical pixel coordinates are: y = floor(yc - dy);
[0139] When the image height is odd, yc is parity corrected according to the position of the center pixel of the image so that the zero voltage reference is consistent with the vertical center of the image.
[0140] Based on the horizontal pixel coordinate x, only mapping points that satisfy 0≤x<W and 0≤y<H participate in pixel weight statistics. Mapping points that are outside the display range of the overlay image are not written into the pixel weight buffer.
[0141] Through the above mapping, the voltage value, vertical alignment reference, display gain, and inverted display status of the ECG sampling points are uniformly converted into the vertical pixel position in the overlay image, without limiting the specific voltage quantization value or device data format.
[0142] like Figure 1 and Figure 2 As shown, in this embodiment, in S3, the set of heartbeats to be drawn is divided into multiple groups according to the number of beats, specifically including:
[0143] Obtain the number of CPU logical processors, and determine the number of worker threads based on the number of processors;
[0144] When the total number of heartbeats is less than or equal to one thousand, all heartbeats are grouped together.
[0145] When the total number of heartbeats is greater than one thousand, the average number of heartbeats per working thread is calculated based on the total number of heartbeats.
[0146] If the average number of heartbeats is less than one thousand, the heartbeat set is divided into several groups in the original order, with each group containing one thousand heartbeats, and the remaining heartbeats with less than one thousand heartbeats are grouped together.
[0147] If the average number of heartbeats is greater than or equal to one thousand, the heartbeat set is divided into several groups in the original order, and the number of heartbeats in each group is the average number of heartbeats.
[0148] In practice, each worker thread is allocated an independent integer pixel weight buffer, and the size of the buffer is consistent with the display area of the overlay image.
[0149] Heartbeats are grouped into sets based on the number of CPUs. Let C be the number of CPU logical processors, T be the number of working threads, and N be the total number of heartbeats to be processed.
[0150] After obtaining the number of CPU logical processors C, when C≤4, T=C, and when C>4, T=C-1, while ensuring T≥1, so that when the number of processors is greater than 4, one logical processor is reserved for interface response and other system tasks, reducing the impact of overlay graph calculation on the doctor's operation process.
[0151] When N≤1000, all heartbeats are processed as a group to avoid the overhead of thread creation and buffer allocation exceeding the benefits of parallel computing;
[0152] When N > 1000, first calculate the average number of groups:
[0153] G0 = floor(N / T);
[0154] The number of heartbeats G in each normal group is:
[0155] G = max(G0, 1000);
[0156] G takes the maximum value between G0 and 1000. That is, when G0 is greater than or equal to 1000, the number of heartbeats G in each normal group is the average number of groups G0. When G0 is less than 1000, the heartbeat set is divided into several groups in the original order. The preceding threads process 1000 heartbeats respectively, and the remaining heartbeats are assigned to the last effective thread as a group for processing.
[0157] In S3, during the process of allocating an independent pixel weight buffer for each worker thread, the buffer size is consistent with the display area of the overlay image.
[0158] Pixel weight buffer:
[0159] Bt, t∈[1,T];
[0160] Each buffer contains W×H integer elements and is initialized to zero;
[0161] When using column-based storage, the buffer index corresponding to the pixel coordinate (x,y) is: Index(x,y) = x × H + y;
[0162] Each thread only writes to its own private buffer, and does not write directly to other threads' buffers or draw image colors directly, thereby avoiding data races and lock waits caused by multiple threads modifying the same pixel at the same time.
[0163] like Figure 3 As shown, in this embodiment, the heartbeat waveform points are converted into image pixel coordinates according to the mapping relationship, and then the midpoint of adjacent sampling points is calculated, and the difference between adjacent sampling points is statistically analyzed.
[0164] In practice, each thread iterates through the heartbeats it is responsible for in turn. For each heartbeat, according to the aforementioned coordinate mapping relationship, each sampling point is converted into pixel coordinates (x, y).
[0165] If the pixel coordinates are within the image range, then increment the weight value of the corresponding position by one: Bt(x,y)=Bt(x,y)+1;
[0166] Where Bt(x,y) represents the cumulative number of times the heartbeat waveform responsible for the t-th thread passes through pixel (x,y). This process only performs ECG data reading, coordinate transformation, buffer addressing, and integer accumulation, and does not call the curve drawing interface one by one.
[0167] To reduce waveform discontinuities caused by coordinate mapping between adjacent sampling points and improve the continuity of the waveform trajectory, interpolation statistics are performed on adjacent sampling points to calculate the midpoint between adjacent sampling points.
[0168] Let the horizontal pixel coordinates of adjacent sampling points be x1 and x2, and the vertical offsets be dy1 and dy2, then the interpolation position is:
[0169] xm = floor((x1+x2) / 2);
[0170] dym = (dy1 + dy2) / 2;
[0171] ym = floor(yc - dym);
[0172] If the interpolated pixel (xm, ym) is within the image range, increment the weight value of that pixel position by one: Bt(xm, ym) = Bt(xm, ym) + 1;
[0173] By statistically analyzing the intermediate positions of the original sampling points and adjacent sampling points, waveform breaks caused by sampling point compression mapping are reduced.
[0174] like Figure 2As shown, in this embodiment, in S5, merging the pixel weight buffers of each thread to obtain the global pixel weight buffer includes:
[0175] S51, Select a pixel weight buffer as the global pixel weight buffer;
[0176] S52, add the same index elements in the remaining pixel weight buffers to the global pixel weight buffer one by one;
[0177] S53, after merging, releases the private pixel weight buffers of other threads.
[0178] In practice, after all worker threads have completed their tasks, the private buffers of each thread are accumulated according to the same pixel position. Let the global pixel weight buffer be B, then:
[0179] B(x,y)=ΣBt(x,y), t=1 to T;
[0180] Then, select a thread buffer as the global buffer, and add the elements with the same index from other buffers to the global pixel weight buffer one by one.
[0181] like Figure 1 and Figure 2 As shown, in this embodiment, in S6, a density-color image is generated based on pixel weights, and the output overlay image includes:
[0182] S61, calculate the average pixel weight according to the weight distribution of the image column, and calculate the density threshold based on the average pixel weight and the preset first density coefficient and second density coefficient.
[0183] Calculating the average pixel weight by image column includes:
[0184] Calculate the total weight Sx of all non-zero pixels in the column, and count the number of non-zero pixels Qx;
[0185] If Qx is greater than 0, the average pixel Ax is equal to the ratio of Sx to Qx;
[0186] When Qx equals 0, it means that no heartbeat waveform passes through this column, and the entire column retains its background color;
[0187] S62 compares the average pixel weight with the density threshold and maps different pixel density regions to different colors according to the preset color mapping rules;
[0188] The pixel weights are compared with the density threshold to determine whether the region is a region without a heartbeat waveform, a low-density region, a medium-density region, or a high-density region. The regions without a heartbeat waveform are mapped to black, the low-density regions to green, the medium-density regions to yellow, and the high-density regions to red, forming a superimposed image of density and color.
[0189] S63, when the number of non-zero pixels in a column is less than the preset number, a reduced density threshold is used to map different pixel density areas to different colors.
[0190] In practice, for the x-th column, the sum of the weights of non-zero pixels is: Sx=ΣB(x,y), where B(x,y)>0;
[0191] The number of non-zero pixels in this column is: Qx=ΣI(B(x,y)>0);
[0192] Where I is the conditional counting function, specifically:
[0193] When Qx > 0, the average pixel weight of this column is Ax = Sx / Qx;
[0194] When Qx=0, it means that no heartbeat waveform passes through this column, and the entire column remains black.
[0195] By using only non-zero weighted pixels to calculate the average, the excessive reduction of the average weight by a large number of background pixels is avoided.
[0196] During the color mapping process, a first density coefficient L1 and a second density coefficient L2 are set, satisfying: L2 > L1 > 0. In one implementation, L1 = 1.4 and L2 = 2.4 can be set.
[0197] For a pixel (x,y) in the x-th column, let its pixel weight be K=B(x,y);
[0198] Under normal circumstances, the color mapping rule is:
[0199] K=0, mapped to black, indicating that no heartbeat waveform passes through;
[0200] 0 < K ≤ Ax × L1, mapped to green, representing a low-density region;
[0201] Ax×L1<K≤Ax×L2, mapped to yellow, represents a medium-density region;
[0202] K > Ax × L2, mapped to red, represents a high-density region.
[0203] When the number of non-zero pixels in a column Qx is less than the preset number Q0, a reduced density threshold is used. Q0 is the preset threshold for the number of non-zero pixels. In one implementation, Q0 can be set to 60.
[0204] When Qx < Q0, the color mapping rule is adjusted as follows:
[0205] When 0 < K ≤ Ax, the mapping is green;
[0206] When Ax < K ≤ Ax × L1, the mapping is yellow;
[0207] When K > Ax × L1, the mapping is red;
[0208] By lowering the threshold for columns with fewer non-zero pixels, it is possible to avoid failing to highlight high-density areas when the local waveform range is narrow.
[0209] In this invention, the system creates an image with a width of W and a height of H, initializes the background to black, then traverses the global pixel weight buffer, determines the corresponding color based on the weight of each pixel, the average weight of the column, and the density coefficient, and finally generates an electrocardiogram overlay.
[0210] When a doctor adjusts the display gain, display duration, alignment, reverse display status, image size, or heartbeat set, the system re-executes the sampling point mapping and pixel weight statistics.
[0211] When doctors adjust only the first and second density coefficients, they can reuse the already generated global pixel weight buffer, only re-performing the column average weight calculation and color mapping, without having to traverse all heartbeats again.
[0212] The above method converts the drawing of a large number of heartbeat waveforms into private pixel weight statistics of multiple CPU threads, and then merges and colors them uniformly after the threads are completed. This avoids lock contention caused by multiple threads drawing the same image directly, and does not rely on GPU, OpenCL or specific graphics card drivers. It is suitable for Windows XP and other devices that do not have a stable GPU computing environment.
[0213] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from its spirit or essential characteristics. Therefore, the embodiments should be considered in all respects as exemplary and non-limiting, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims.
[0214] Furthermore, it should be understood that although this specification describes embodiments, not every embodiment contains only one independent technical solution. This narrative style is merely for clarity. Those skilled in the art should consider the specification as a whole, and the technical solutions in each embodiment can also be appropriately combined to form other embodiments that can be understood by those skilled in the art.
Claims
1. A method for drawing electrocardiogram overlays based on pixel weight statistics, characterized in that, include: Obtain the set of heartbeats for the overlay image to be drawn, and extract the R-point position or alignment reference point corresponding to each heartbeat; Obtain the display parameters of the overlay image, and use the display parameters to establish the mapping relationship between sampling points and pixel coordinates; The heartbeat set to be drawn is divided into multiple groups according to the number of heartbeats. Each group is processed by a CPU worker thread, and an independent pixel weight buffer is allocated to each worker thread. In the pixel weight buffer, each working thread converts the corresponding heartbeat waveform point into image pixel coordinates according to the mapping relationship; Merge the pixel weight buffers of each thread to obtain the global pixel weight buffer; A density color image is generated based on pixel weights, forming an overlay image which is then displayed.
2. The ECG overlay plotting method based on pixel weight statistics according to claim 1, characterized in that, After extracting the alignment reference points corresponding to the heartbeats, the alignment reference points of each heartbeat are corrected according to the preset alignment method. The alignment methods include at least: Align with point R; Vertical alignment is performed using the voltage at point R; Search for the highest voltage point within a preset range near point R, and align with the highest voltage point; Search for the lowest voltage point within a preset range near point R, and align with the lowest point; Based on the main orientation of the R wave in the heartbeat set, the highest or lowest point is automatically selected for alignment.
3. The ECG overlay plotting method based on pixel weight statistics according to claim 1, characterized in that, The overlay display parameters include at least the display area width, display area height, display gain, display duration, alignment method, and reverse display parameters.
4. The method for drawing an electrocardiogram overlay based on pixel weight statistics according to claim 3, characterized in that, The establishment of the mapping relationship between sampling points and pixel coordinates includes: The sampling rate conversion factor is determined based on the ratio of the actual sampling rate to the reference sampling rate, and the horizontal sampling multiple is determined based on the sampling rate conversion factor and the display duration multiple. Determine the number of sampling points to be read based on the display area width, the horizontal sampling multiple, and the standard horizontal multiple; The number of sampling points is obtained based on the parameter of the correspondence between sampling points and pixels and the width of the display area, and the display duration is calculated based on the sampling rate. Determine the starting point for reading; the starting point can be one-quarter, one-half, or three-quarters of the width of the display area. A number of sampling points are uniformly mapped onto the width of the horizontal display area; The voltage values, vertical alignment reference, display gain, and reverse display parameters of the ECG sampling points are converted into the vertical pixel positions in the overlay image.
5. The method for drawing an electrocardiogram overlay based on pixel weight statistics according to any one of claims 1-4, characterized in that, The set of heartbeats to be drawn is divided into multiple groups according to their quantity, including: Obtain the number of CPU logical processors, and determine the number of worker threads based on the number of processors; When the total number of heartbeats is less than or equal to one thousand, all heartbeats are grouped together. When the total number of heartbeats is greater than one thousand, the average number of heartbeats per working thread is calculated based on the total number of heartbeats. If the average number of heartbeats is less than one thousand, the heartbeat set is divided into several groups in the original order, with each group containing one thousand heartbeats, and the remaining heartbeats with less than one thousand heartbeats are grouped together. If the average number of heartbeats is greater than or equal to one thousand, the heartbeat set is divided into several groups in the original order, and the number of heartbeats in each group is the average number of heartbeats.
6. The method for drawing an electrocardiogram overlay based on pixel weight statistics according to any one of claims 1-4, characterized in that, After converting the heartbeat waveform points into image pixel coordinates, the midpoint of adjacent sampling points is calculated, and the difference between adjacent sampling points is statistically analyzed.
7. The method for drawing an electrocardiogram overlay based on pixel weight statistics according to any one of claims 1-4, characterized in that, Select one pixel weight buffer as the global pixel weight buffer, and add the elements with the same index from the other pixel weight buffers to the global pixel weight buffer one by one. After merging, release the private pixel weight buffers of other threads.
8. The method for drawing an electrocardiogram overlay based on pixel weight statistics according to any one of claims 1-4, characterized in that, Generating a density-color image based on pixel weights includes: The average pixel weight is calculated based on the weight distribution of the image column, and the density threshold is calculated based on the average pixel weight and the preset first density coefficient and second density coefficient. The average pixel weight is compared with the density threshold, and different pixel density regions are mapped to different colors according to the preset color mapping rules. When the number of non-zero pixels in a column is less than a preset number, a reduced density threshold is used to map different pixel density regions to different colors.
9. The method for drawing an electrocardiogram overlay based on pixel weight statistics according to claim 8, characterized in that, The calculation of average pixel weights by image column includes: Calculate the total weight Sx of all non-zero pixels in the column, and count the number of non-zero pixels Qx; If Qx is greater than 0, the average pixel Ax is equal to the ratio of Sx to Qx; When Qx equals 0, it means that no heartbeat waveform passes through the entire column, and the entire column retains its background color.
10. The method for drawing an electrocardiogram overlay based on pixel weight statistics according to claim 8, characterized in that, In the process of mapping different pixel density regions to different colors, the pixel weights are compared with the density thresholds to determine whether the region is a heartbeat-free waveform region, a low-density region, a medium-density region, or a high-density region. The heartbeat-free waveform region is mapped to black, the low-density region to green, the medium-density region to yellow, and the high-density region to red.