2013-05-06 58 views
-1

我必須在ios上找到ECG波形的峯值,因此我首先應用了顏色檢測代碼來檢測黑色波形,然後通過ios找到了該像素的座標使用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值,所以任何人都可以幫助我,我怎麼能找到它?

回答

0

首先定義你想要治療的高峯。

如果一個簡單的局部極大值,然後在相鄰索引中搜索值序列a,b,c,其中一個< b> c。儘管它們可以很容易地檢測到充滿峯值的靜止段,但它們甚至允許相等。

可能是一種更好的方法在平滑曲線上執行此搜索。

+0

感謝您的回覆,您可以查看此圖片http://www.google.com.pk/imgres?imgurl=http://www.cvphysiology.com/Arrhythmias/ECG%2520trace%2520with%2520grid.gif&imgrefurl=http ://www.cvphysiology.com/Arrhythmias/A009.htm&h=317&w=350&sz=14&tbnid=RVV0Aj8MifiGoM:&TBNH = 91&tbnw = 100&變焦= 1&USG = __ ytoheH7aeVESI41K3pCezUBpOjI =&的docID = e7Ao78HjT4zcMM&SA = X&EI = sCuIUdy_HaLw4QSU3ICIBw&VED = 0CDUQ9QEwAQ&從該圖像DUR = 256 你可以知道我想要得到的結果 – 2013-05-06 22:16:37

+0

另一種方法是以積極和消極部分的形式在一階導數中搜索峯值。你可以微調你想接受的陡峭峯值。 – jmihalicza 2013-05-06 22:21:24

+0

是的,我知道但實際上我沒有找到如何編碼和添加上面的代碼,你可以請爲我做嗎?我會對你很好:| – 2013-05-06 22:24:49