jestem konwersji ciimage do monochromatycznych, wycinek z CICrop i działa Sobel wykrywać krawędzie #if sekcji na dole jest używany do wyświetlania spowodowaćCIImage (IOS): Dodawanie splot 3x3 po filtr monochromatyczny jakoś przywraca kolor
CIImage *ci = [[CIImage alloc] initWithCGImage:uiImage.CGImage];
CIImage *gray = [CIFilter filterWithName:@"CIColorMonochrome" keysAndValues:
@"inputImage", ci, @"inputColor", [[CIColor alloc] initWithColor:[UIColor whiteColor]],
nil].outputImage;
CGRect rect = [ci extent];
rect.origin = CGPointZero;
CGRect cropRectLeft = CGRectMake(0, 0, rect.size.width * 0.2, rect.size.height);
CIVector *cropRect = [CIVector vectorWithX:rect.origin.x Y:rect.origin.y Z:rect.size.width* 0.2 W:rect.size.height];
CIImage *left = [gray imageByCroppingToRect:cropRectLeft];
CIFilter *cropFilter = [CIFilter filterWithName:@"CICrop"];
[cropFilter setValue:left forKey:@"inputImage"];
[cropFilter setValue:cropRect forKey:@"inputRectangle"];
// The sobel convoloution will produce an image that is 0.5,0.5,0.5,0.5 whereever the image is flat
// On edges the image will contain values that deviate from that based on the strength and
// direction of the edge
const double g = 1.;
const CGFloat weights[] = { 1*g, 0, -1*g,
2*g, 0, -2*g,
1*g, 0, -1*g};
left = [CIFilter filterWithName:@"CIConvolution3X3" keysAndValues:
@"inputImage", cropFilter.outputImage,
@"inputWeights", [CIVector vectorWithValues:weights count:9],
@"inputBias", @0.5,
nil].outputImage;
#define VISUALHELP 1
#if VISUALHELP
CGImageRef imageRefLeft = [gcicontext createCGImage:left fromRect:cropRectLeft];
CGContextDrawImage(context, cropRectLeft, imageRefLeft);
CGImageRelease(imageRefLeft);
#endif
teraz gdy 3x3 splotu jest częścią rurociągu ciimage czym część obrazu uruchomić wykrywania krawędzi na pojawiającej się na szarym ale gdy CIConvolution3X3 przyrostek jest częścią rurociągu przetwarzania kolory magiczną pojawiają się. Dzieje się tak niezależnie od numeru , jeśli używam prefiksu CIColorMonochrome lub CIPhotoEffectMono w celu usunięcia koloru. Jakieś pomysły, jak utrzymać kolor aż do samego końca potoku? tnx
UPD: nie zaskakująco prowadzenie ropy niestandardowe jądro monochromatycznego taki jak ten
kernel vec4 gray(sampler image)
{
vec4 s = sample(image, samplerCoord(image));
float r = (s.r * .299 + s.g * .587 + s.b * 0.114) * s.a;
s = vec4(r, r, r, 1);
return s;
}
zamiast przy użyciu standardowych filtrów mono z wyników Apple w dokładnie tym samym problemu z kolorem wraca kiedy 3x3 splotu jest częścią mojego potoku
Wygląda obiecująco. – Bobjt