-1

我必须在 ios 上找到 ECG 波形的峰值,因此我首先应用颜色检测代码来检测黑色波形,然后通过

   CGImageRef imgSource = self.ImageView.image.CGImage;
CFDataRef m_DataRed1 = CGDataProviderCopyData(CGImageGetDataProvider(imgSource));
CGFloat myheight;
CGFloat mywidth;
myheight= CGImageGetHeight(imgSource);
mywidth = CGImageGetWidth(imgSource);
UInt8 *dataOrignal = (UInt8 *)CFDataGetBytePtr(m_DataRed1);
double lenghtSource = CFDataGetLength(m_DataRed1);
NSLog(@"lenght : %f",lenghtSource);

int bytesPerPixel_ = CGImageGetBitsPerPixel(imgSource)/8;
size_t bytesPerRow = CGImageGetBytesPerRow(imgSource);
NSLog(@"height = %f, width = %f, bytesperPixel = %d",myheight,mywidth,bytesPerPixel_);
for(int x = 0; x < mywidth; x++)
{
    for(int y = 0; y < myheight; y++)
    {
        int pixelStartIndex = 4*((bytesPerRow*x)+y);
        if (pixelStartIndex <= lenghtSource) {
            UInt8 alphaVal = dataOrignal[pixelStartIndex];
            UInt8 redVal = dataOrignal[pixelStartIndex + 1];
            UInt8 greenVal = dataOrignal[pixelStartIndex + 2];
            UInt8 blueVal = dataOrignal[pixelStartIndex + 3];

            if(redVal == 236 || blueVal == 236 || greenVal == 236)
            {
                dataOrignal[pixelStartIndex + 1] = 205;
                dataOrignal[pixelStartIndex +2] = 25;
                dataOrignal[pixelStartIndex+3]= 55;
                NSLog(@"x %d, y = %d, index = %d", x, y,pixelStartIndex);
            }

        }
    }                

}

NSUInteger width = CGImageGetWidth(imgSource); //202
NSUInteger height = CGImageGetHeight(imgSource);//173
size_t bitsPerComponent = CGImageGetBitsPerComponent(imgSource);
size_t bitsPerPixel = CGImageGetBitsPerPixel(imgSource);




NSLog(@"the width = %u and height=%u of the image is ",width,height );
NSLog(@"the bits per component is %zd", bitsPerComponent);
NSLog(@"the bits per pixel is %zd", bitsPerPixel);
NSLog(@"the bytes per row is %zd" , bytesPerRow);

CGColorSpaceRef colorspace = CGImageGetColorSpace(imgSource);
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imgSource);
CFDataRef newData = CFDataCreate(NULL, dataOrignal, lenghtSource);
CGDataProviderRef provider = CGDataProviderCreateWithCFData(newData);

CGContextRef context = CGBitmapContextCreate(newData, width, height, bitsPerComponent, bytesPerRow, colorspace, bitmapInfo);
CGPoint point = CGContextGetTextPosition(context);
NSInteger xx =  point.x;

// 点.y;

NSLog(@"this is the value of x axis %d",xx);

CGImageRef newImg = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, bitmapInfo, provider, NULL, true, kCGRenderingIntentDefault);





UIImage *newImage1 = [UIImage imageWithCGImage:newImg];
self.ImageView.image = newImage1;

现在我想找到峰值的 x 和 y 值,所以任何人都可以帮助我,我怎么能找到它?

4

1 回答 1

0

首先定义你想要处理的峰。

如果是简单的局部最大值,则在相邻索引中搜索值 a、b、c 的序列,其中 a < b > c。甚至允许等式,尽管它们可以很容易地检测到充满峰值的固定段。

可能是在平滑曲线上进行此搜索的更好方法。

于 2013-05-06T22:14:57.520 回答