ios 图像翻转_在iOS 14中使用计算机视觉的图像差异

ios 图像翻转

Human eyes are very receptive to visual representations. Similarly, computer vision enables systems to understand and process images.

人眼很容易接受视觉表现。 同样,计算机视觉使系统能够理解和处理图像。

Core Image and Vision are the two main pillars of Computer Vision in iOS. During WWDC 2020 Apple pushed the envelope for both of them.

Core Image和Vision是iOS中计算机视觉的两个主要Struts。 在WWDC 2020期间,苹果公司为两者推波助澜。

Core Image in iOS 14 now includes a few new built-in filters for image processing. Specifically, we have a CIColorThreshold filter to convert an image into just black and white by setting threshold value as well as another CIColorThresholdOtsu which determines the appropriate threshold from the image’s histogram.

iOS 14中的Core Image现在包括一些用于图像处理的新内置过滤器。 具体来说,我们有一个CIColorThreshold过滤器,可以通过设置阈值将图像转换为黑白图像,以及另一个CIColorThresholdOtsu ,它可以根据图像的直方图确定适当的阈值。

More importantly, we can now compare two images using the new CIColorAbsoluteDifference filter — our main focus in this article.

更重要的是,我们现在可以使用新的CIColorAbsoluteDifference过滤器比较两个图像,这是本文的重点。

In the following sections, we’ll explore the use cases that can be achieved by analyzing the difference between images.

在以下各节中,我们将探讨通过分析图像之间的差异可以实现的用例。

绝对像差 (Absolute Image Difference)

This image processing task involves computing the absolute difference of each pixel across two images and adding them up.

该图像处理任务涉及计算两个图像上每个像素的绝对差并将其相加。

In doing so, we get a new transformed image that shows the variations across the two images.

这样,我们得到了一个新的变换图像,该图像显示了两个图像之间的变化。

In the new Core Image filter, if the two images are exactly, the same, our output image would be black.

在新的Core Image滤镜中,如果两个图像完全相同,则我们的输出图像将为黑色。

By comparing color differences across images we can:

通过比较图像之间的色差,我们可以:

  • Analyze video frames. For example, we can determine if the frames are consistent or there’s some shadow in any of the frames.

    分析视频帧。 例如,我们可以确定帧是否一致或任何帧中是否有阴影。
  • Anamoly detection to find outliers that can be missed by the naked eye. This is useful for spotting differences between images such as if a credit card or currency note has missing symbols.

    进行异常检测以找到肉眼可能遗漏的异常值。 这对于发现图像之间的差异很有用,例如信用卡或纸币的符号是否缺失。

Next up, we’ll explore a few examples of comparing two images.

接下来,我们将探讨一些比较两个图像的示例。

核心图像过滤器:CIColorAbsoluteDifference (Core Image Filter: CIColorAbsoluteDifference)

Let’s create a new SwiftUI application that performs image processing.

让我们创建一个执行图像处理的新SwiftUI应用程序。

Core Image requires setting the input CIImage(which we’ll convert from UIImage) onto the CIFilter. Subsequently, we can set thresholds if any, and retrieve the outputImage instance from the filter. That outputImage instance is basically a copy of the inputImage which is then passed into CIContext’s function createCGImage to perform the transformation.

Core Image需要将输入CIImage (我们将从UIImage转换为输入)设置到CIFilter 。 随后,我们可以设置阈值(如果有),并从过滤器中检索outputImage实例。 这outputImage例如基本的副本inputImage ,然后传递到CIContext的功能createCGImage执行转换。

CIContext is where all the image processing takes place.

CIContext是所有图像处理发生的地方。

发现SwiftUI中图像之间的差异 (Spot The Difference Between Images in SwiftUI)

The following example shows the classic “spot the difference in images” puzzle. But with computer vision.

以下示例显示了经典的“发现图像差异”难题。 但是具有计算机视觉。

Image for post

CIFilter.colorAbsoluteDifference() creates the CIFilter and we passed the two images on it.

CIFilter.colorAbsoluteDifference()创建CIFilter,我们在其上传递了两个图像。

We can also transform the two images into grayscale before comparing them.

在比较它们之前,我们还可以将两个图像转换为灰度图像。

水印检测/提取 (Watermark Detection/Extraction)

It’s common to come across a task where you need to ensure that a watermark or logo overlay is set over the image. Again, using the CIColorAbsoluteDifference we can determine that as shown below:

通常需要执行一项任务,以确保在图像上设置水印或徽标覆盖。 同样,使用CIColorAbsoluteDifference我们可以确定如下所示:

Image for post

信用卡异常检测 (Credit Card Anomaly Detection)

Scanning credit cards in our mobile applications and extracting the digits is a fairly common computer vision task.

在我们的移动应用程序中扫描信用卡并提取数字是相当常见的计算机视觉任务。

We can further leverage the power of the above Core Image Filter to determine if the credit card’s image hasn’t tampered. Moreover, we can keep a reference credit card image that’s blank and compare it with a scanned image to only extract the digits.

我们可以进一步利用上述“核心图像过滤器”的功能来确定信用卡图像是否未被篡改。 此外,我们可以保留空白的参考信用卡图像,并将其与扫描的图像进行比较,以仅提取数字。

The following example shows how to do both of these things:

下面的示例演示如何执行这两项操作:

Image for post
Screengrabs by author
作者的屏幕截图

In the left-hand side image, to fully detect if outlier/anomaly is present using computer vision, we can extend the above example by comparing the output image with an opaque black image.

在左侧图像中,为了使用计算机视觉完全检测出异常值/异常,我们可以通过将输出图像与不透明的黑色图像进行比较来扩展上述示例。

The full source code of the above SwiftUI + CoreImage application is available in this Github Repository.

上面的SwiftUI + CoreImage应用程序的完整源代码可在此Github存储库中找到

结论 (Conclusion)

Apple’s image processing framework CoreImage is handy for image transformations and augmentations when preparing datasets.

Apple的图像处理框架CoreImage在准备数据集时可方便地进行图像转换和扩充。

We discussed a new filter CIColorAbsoluteDifference available in iOS 14 that compares two images by the color of each pixel(without the need of OpenCV).

我们讨论了iOS 14中提供的新滤镜CIColorAbsoluteDifference该滤镜通过每个像素的颜色比较两个图像(无需OpenCV)。

This is useful in spotting blemishes across images, determining and removing duplicate images from a video or dataset.

这对于发现图像上的瑕疵,确定视频或数据集中的重复图像并从中删除重复图像很有用。

That’s it for this one. Thanks for reading.

这就是它了。 谢谢阅读。

翻译自: https://towardsdatascience.com/image-difference-using-computer-vision-in-ios-14-7753b8d61e82

ios 图像翻转

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值