如何檢測兩幅圖像之間的差異,創建不同區域的蒙版以處理兩幅圖像共有的區域(例如高斯模糊)?根據兩幅圖像(iPhone)之間的差異創建一個蒙版
編輯:我目前使用此代碼來獲取像素的RGBA值:
+ (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)xx andY:(int)yy count:(int)count
{
NSMutableArray *result = [NSMutableArray arrayWithCapacity:count];
// First get the image into your data buffer
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc(height * width * 4);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
// Now your rawData contains the image data in the RGBA8888 pixel format.
int byteIndex = (bytesPerRow * yy) + xx * bytesPerPixel;
for (int ii = 0 ; ii < count ; ++ii)
{
CGFloat red = (rawData[byteIndex] * 1.0)/255.0;
CGFloat green = (rawData[byteIndex + 1] * 1.0)/255.0;
CGFloat blue = (rawData[byteIndex + 2] * 1.0)/255.0;
CGFloat alpha = (rawData[byteIndex + 3] * 1.0)/255.0;
byteIndex += 4;
UIColor *acolor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
[result addObject:acolor];
}
free(rawData);
return result;
}
的問題是,將圖像從iPhone的相機拍攝,使他們並不完全一樣。我需要創建幾個像素的區域並提取該區域的一般顏色(也許通過將RGBA值相加併除以像素數量)。我怎麼能做到這一點,然後把它翻譯成CGMask?
我知道這是一個複雜的問題,所以任何幫助表示讚賞。
謝謝。
你好科裏,代碼是非常有用的,它設法產生在任何一張照片都不存在的元素。但是,它似乎也產生了黑色背景,而不是透明背景。有沒有辦法去除黑色背景? – wahkiz 2013-02-20 08:23:42