使用ios查找图形的峰值

时间:2013-05-06 22:10:38

标签: iphone ios image-processing graph

我必须在ios上找到心电图波形的峰值,所以我首先应用了颜色检测代码来检测那个黑色波形,然后我找到了那些像素的坐标

   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;

// point.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值,所以任何人都可以帮助我,我怎么能找到它?

1 个答案:

答案 0 :(得分:0)

首先定义您想要处理的峰值。

如果是简单的局部最大值,则在相邻索引中搜索值a,b,c的序列,其中a&lt; b> C。 或者甚至允许平等,尽管它们可以很容易地检测出充满峰值的静止段。

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

相关问题