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.
以下示例顯示了經典的“發現圖像差異”難題。 但是具有計算機視覺。
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我們可以確定如下所示:
信用卡異常檢測 (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:
下面的示例演示如何執行這兩項操作:
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 圖像翻轉
總結
以上是生活随笔為你收集整理的ios 图像翻转_在iOS 14中使用计算机视觉的图像差异的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 富士通发布超轻笔记本,仅 689g 重
- 下一篇: 现在的蔬菜水果比以前的难吃,不是你的错觉