¿Cómo puedo detectar la diferencia entre 2 imágenes, creando una máscara del área diferente para procesar el área común a ambas imágenes (desenfoque gaussiano, por ejemplo)?Crear una máscara a partir de la diferencia entre dos imágenes (iPhone)
EDIT: actualmente estoy usando este código para obtener el valor RGBA de píxeles:
+ (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;
}
El problema es que las imágenes se capturan desde la cámara del iPhone para que no son exactamente la misma posición. Necesito crear áreas de un par de píxeles y extraer el color general del área (¿tal vez sumando los valores RGBA y dividiendo por el número de píxeles?). ¿Cómo podría hacer esto y luego traducirlo a CGMask?
Sé que esta es una pregunta compleja, por lo que cualquier ayuda es apreciada.
Gracias.
Hola Cory, el código es muy útil, logró producir los elementos que no están presentes en ninguna de las fotos. Sin embargo, parece que también produce un fondo negro, a diferencia de un fondo transparente. ¿Hay alguna manera de eliminar el fondo negro? – wahkiz