如何检测两幅图像之间的差异,创建不同区域的蒙版以处理两幅图像共有的区域(例如高斯模糊)?根据两幅图像(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