使用CIImage“内部”(像边缘)检测?

问题描述:

我试图检测街景图像中建筑物的轮廓。结果应该与你在海报上看到的相似,天空是白色的,建筑物是黑色的。这与典型的边缘检测不同,它可以在整个图像中找到边缘。使用CIImage“内部”(像边缘)检测?

我试图通过提高图像的对比度来完成这项工作,以便完全清除天空。我打算使用CIFilter对结果进行边缘检测。我仍然认为这可能会起作用,但它对我来说是一种嘲讽,我从未从事过图像处理。

因此,在我走得更远之前,有没有人知道这个预滚版本?

好了,所以这里是我如何解决这个...

开始使用CIImage把它变成一个灰度图像。我使用了Noir,因为它似乎产生了更加鲜明的对比图像。

我然后施加一个第二过滤器,以提高对比度5.

其结果是,纯粹是黑色和白色,黑色像素是所述内部的图像。

只是偶然发现你的问题。

让我先介绍一下我喜欢选择的方法,如果我使用Apple提供的滤镜。

苹果公司在“图形工具Xcode的”捆绑一定的图形工具 - 请有文档在这里看看他们:https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_custom_filters/ci_custom_filters.html#//apple_ref/doc/uid/TP30001185-CH6-BCICGCJF

如果你有他们,寻找“石英作曲家”。 使用这一伟大的介绍在这里: https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/QuartzComposerUserGuide/qc_tutorial/qc_tutorial.html

这就是你需要链中的过滤器(由Apple提供),让您得到最佳的出你的图像后处理的。 我喜欢这种方法,因为它比在代码中使用过滤器参数更快 - 重新编译和构建并运行。

当你得到了很好的结果后,你很满意,把过滤器(带有参数)翻译成code et瞧。你们都成立了。

现在回到你的基本想法。在图像上进行对比度增强和最终边缘检测。这就是它的样子(不要指望我的参数)

CIImage *outputImage = ciImage; 
// Your Idea to enhance contrast. 
CIFilter *ciColorMonochrome = [CIFilter filterWithName:@"CIColorMonochrome"]; 
[ciColorMonochrome setValue:outputImage forKey:kCIInputImageKey]; 
[ciColorMonochrome setValue:@(1) forKey:@"inputIntensity"]; 
[ciColorMonochrome setValue:[[CIColor alloc] initWithColor:[UIColor whiteColor]] forKey:@"inputColor"];// Black and white 
outputImage = [ciColorMonochrome valueForKey:kCIOutputImageKey]; 

// Now go on with edge detection 
CIImage *result = [filter valueForKey:kCIOutputImageKey]; 
CIFilter *ciEdges = [CIFilter filterWithName:@"CIEdges"]; 
[ciEdges setValue:outputImage forKey:kCIInputImageKey]; 
[ciEdges setValue:@(5) forKey:@"inputIntensity"]; 
outputImage = [ciEdges valueForKey:kCIOutputImageKey];