简体   繁体   English

在 C++ 中的一系列数字中查找重复模式

[英]Finding repeated pattern in a series of numbers in C++

I am trying to implement an auto grid detection system for an electrocardiogram, ecg, paper see the figure below.The idea behind is to add the pixel values(only considered the red channel) by going through pixel by pixel of the ecg image as shown in the code below.我正在尝试为心电图、心电图、纸实现自动网格检测系统,请参见下图。背后的想法是通过逐个像素地检查心电图图像来添加像素值(仅考虑红色通道),如图所示在下面的代码中。

QImage image("C:/Users/.../Desktop/ECGProject/electrocardiogram.jpg");
std::vector<int> pixelValues;
for (int y = 0; y < img.height(); y++)
{
   int rowSumR = 0, rowSumG = 0, rowSumB = 0;
   for (int x = 0; x < img.width(); x++)
   {
       QRgb rgb = img.pixel(x, y);
       rowSumR += qRed(rgb);
   }
   rowSumR /= img.width();
   const int &value = rowSumR/4;
   pixelValues.push_back(value)
}

The vector pixelValues contains summed values which has repeated pattern in ay direction.矢量pixelValues包含在 y 方向上具有重复模式的总和值。 The goal is to detect those repeated pattern (for instance the line drawn in black color on in the ecg image is the interest or what I am looking to identify in ay direction).目标是检测那些重复的模式(例如,在心电图图像上以黑色绘制的线是兴趣或我希望在任何方向上识别的内容)。 I also draw the summed pixel value in y direction using matlab(see the figure below) and the red circles are the pattern I am interested in. Any suggestion/algorithm to find these repeated pattern would be appreciated.我还使用 matlab 绘制了 y 方向的总像素值(见下图),红色圆圈是我感兴趣的模式。任何找到这些重复模式的建议/算法将不胜感激。 [![Ecg paper][1]][1] [![enter image description here][2]][2] [![心电图][1]][1] [![在此处输入图像描述][2]][2]

If you need to identify the number of bold red grid lines and "cut off" the similar patterns associated with each "period" in it I would suggest using of pitch tracking algorithms used in speech processing.如果您需要识别粗体红色网格线的数量并“切断”与其中每个“周期”相关的类似模式,我建议使用语音处理中使用的音高跟踪算法。 One such approach, which computes the so-called pitch track is described in this work: https://www.diva-portal.org/smash/get/diva2:14647/FULLTEXT01.pdf If you need help implementing that algorithm I can do it for you if you provide me the data.在这项工作中描述了一种计算所谓音高轨迹的方法: https://www.diva-portal.org/smash/get/diva2:14647/FULLTEXT01.pdf如果您需要帮助来实现该算法,我可以如果您向我提供数据,请为您做。

I wrote a following program for you in matlab:我在 matlab 中为您编写了以下程序:

load data.txt

y = data(:,2);
yr = resample(y,10,1);

xhat = cceps(yr);
figure(1)
subplot(2,1,1)
plot(0:length(xhat)-1,xhat)
subplot(2,1,2)
plot(0:length(yr)-1,yr)

maxima = zeros(10000,1);
cnt = 1;
for i = 2:length(xhat)-1
    
    if xhat(i-1) < xhat(i) && xhat(i+1) < xhat(i)
        maxima(cnt) = i-1;
        cnt = cnt + 1;
    end
end
maxima(cnt:end) = [];
disp(maxima(1:10)/10)

The cepstra are a signal processing tool, which allow detection of periodicity.倒谱是一种信号处理工具,可以检测周期性。 It actually deconvolve signals.它实际上对信号进行去卷积。 Say, in our case, we have an impuls train and some pattern convolved.比如说,在我们的例子中,我们有一个脉冲火车和一些卷积的模式。 Cepstral analysis 'decouples' the impuls train and the pattern.倒谱分析将脉冲序列和模式“解耦”。 The impuls train period results in a maximum at given time spot in the cepstrum.脉冲序列周期导致倒谱中给定时间点的最大值。 If you run this program you can state from the output that the fine grained periodicity has mean period of 3.5 pixels and the greedy periodicity (you marked the corresponding impulses red) has mean period of 23.4 pixels (note the interpolation).如果你运行这个程序,你可以从 output 中得到 state,细粒度周期性的平均周期为 3.5 像素,贪婪周期(你将相应的脉冲标记为红色)的平均周期为 23.4 像素(注意插值)。 Based on this observation you can try by the correlation analysis to refine the local placement of impulses with a technique known from speech processing as pitch-analysis (which is based on the correlation analysis).基于这一观察,您可以尝试通过相关分析来改进脉冲的局部放置,该技术在语音处理中称为音高分析(基于相关分析)。 This last step might be necessary since there are apparent irregularities in peaks placement.这最后一步可能是必要的,因为峰放置存在明显的不规则性。 Let me know if you have further doubts.如果您还有其他疑问,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM