Detectar píxel negro en la imagen iOS

A partir de ahora, estoy buscando en cada píxel 1 por 1 comprobando el color y viendo si es negro ... si no lo está, paso al siguiente píxel. Esto está tomando una eternidad ya que solo puedo verificar aprox. 100 píxeles por segundo (acelerar mi NSTimer congela la aplicación porque no puede verificar lo suficientemente rápido). Entonces, ¿puedo hacer que Xcode devuelva todos los píxeles negros e ignore todo lo demás, así que solo tengo que verificar esos píxeles? Y no todos los píxeles. Estoy tratando de detectar un píxel negro más a la izquierda en mi imagen.

Aquí está mi código actual

- (void)viewDidLoad {
    timer = [NSTimer scheduledTimerWithTimeInterval: 0.01
                                             target: self
                                           selector:@selector(onTick:)
                                           userInfo: nil repeats:YES];
    y1 = 0;
    x1 = 0;
    initialImage = 0;
    height1 = 0;
    width1 = 0;
}

-(void)onTick:(NSTimer *)timer {
    if (initialImage != 1) {
        /*
        IMAGE INITIALLY GETS SET HERE... "image2.image = [blah blah blah];" took this out for non disclosure reasons
        */
        initialImage = 1;
    }
    //image2 is the image I'm checking the pixels of.
    width1 = (int)image2.size.width;
    height1 = (int)image2.size.height;
    CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider(image2.CGImage));
    const UInt32 *pixels = (const UInt32*)CFDataGetBytePtr(imageData);
    if ( (pixels[(x1+(y1*width1))]) == 0x000000) { //0x000000 is black right?
        NSLog(@"black!");
        NSLog(@"x = %i", x1);
        NSLog(@"y = %i", y1);
    }else {
        NSLog(@"val: %lu", (pixels[(x1+(y1*width1))]));
        NSLog(@"x = %i", x1);
        NSLog(@"y = %i", y1);
        x1 ++;
        if (x1 >= width1) {
            y1 ++;
            x1 = 0;
        }
    }
    if (y1 > height1) {
        /*
        MY UPDATE IMAGE CODE GOES HERE (IMAGE CHANGES EVERY TIME ALL PIXELS HAVE BEEN CHECKED
        */
        y1 = 0;
        x1 = 0;
    }

Además, ¿qué pasa si un píxel está realmente cerca del negro pero no del todo negro ... ¿Puedo agregar un margen de error en alguna parte para que aún detecte píxeles que son como el 95% de negro? ¡Gracias

Respuestas a la pregunta(6)

Su respuesta a la pregunta