简体   繁体   English

FFT 获取 2 张图像之间的相似度

[英]FFT to get the similarity between 2 images

My goal is to be able to get the percentage of similarity between 2 images .我的目标是能够获得2 张图像之间的相似度百分比

The point is that my definition of similarity is kind of special in this case.关键是我对相似性的定义在这种情况下有点特殊。

Here are some example of what I want to achieve :以下是我想要实现的一些示例:

Image A图像 A

图像 A

is similar to类似于

Image A bis图像之二

图像之二

HOWEVER,然而,

Image B图像 B

图像 B

is not similar to Image A (or A bis) but is similar to与图像 A(或 A bis)不相似,但类似于

Image B bis图像 B 之二

图像 B 之二

I have already tried to follow the methods described here : Checking images for similarity with OpenCV but it didn't work in my case... In fact a black background was more similar to Image A than Image A bis was to Image A.我已经尝试遵循此处描述的方法: Checking images forsimilarity with OpenCV but it didn't work in my case... 事实上,黑色背景与图像 A 相比,图像 A bis 与图像 A 更相似。

PS : I also tried with colors but the results were the same : PS:我也尝试了颜色,但结果是一样的:

Image A colored图像 A 彩色

图像 A 彩色

Image A bis colored图像 A bis 彩色

图像 A bis 彩色

Image B colored图像 B 彩色

图像 B 彩色

I did more research and someone told me that I could achieve what I wanted using FFT (fast Fourier transform) with openCV (which is what i use).我做了更多的研究,有人告诉我,我可以使用 FFT(快速傅里叶变换)和 openCV(这是我使用的)来实现我想要的。

When applying FFT, this is what I get :应用 FFT 时,这是我得到的:

Image A FFT图像 A FFT

图像 A FFT

Image A bis FFT图像 A bis FFT

图像 A bis FFT

Image B FFT图像 B FFT

图像 B FFT

Image B bis FFT图像 B 之二 FFT

图像 B 之二 FFT

This leads me to these questions : is FFT really the way to go ?这让我想到了这些问题:FFT 真的可行吗? If yes, what can I try to do with my magnitude spectrums ?如果是,我可以尝试用我的幅度谱做什么? If no, is there another way to go that could solve my problem ?如果没有,还有其他方法可以解决我的问题吗?

PS : I would rather not use ML or deep learning id possible. PS:我宁愿不使用 ML 或深度学习 id。

Thanks!谢谢! (and sorry for the quantity of images) (对图片数量感到抱歉)

EDIT 1 :编辑 1

your metric could be number of overlapping pixels divided with the logical and of the two images您的指标可能是重叠像素的数量除以两个图像的逻辑和

Why I haven't done this so far : because sometimes, the form that you see in the examples could be on top of the image wheras the form in my example is at the bottom.为什么到目前为止我还没有这样做:因为有时,您在示例中看到的表单可能位于图像顶部,而我示例中的表单位于底部。 Moreover, one form could be much smaller than the one in the example even though they are still the same.此外,一种形式可能比示例中的形式小得多,即使它们仍然相同。

EDIT 2 :编辑 2

I am looking for the local similarity.我正在寻找当地的相似性。 In fact, the size doesn't matter as long as the form itself is the same shape as the example.实际上,只要表单本身与示例的形状相同,大小并不重要。 Could be much bigger, smaller, located on top, on bottom... It's all about the the shape of the form.可能更大,更小,位于顶部,底部......这完全取决于表格的形状。 However, for form must be in the same direction and rotation.但是,for form 必须在同一个方向和旋转。

For instance, here are two images that must be classified as Image A :例如,这里有两个必须归类为 Image A 的图像:

图像之二之二 图像 A bis bis bis

EDIT 3 :编辑 3

The pictures you see are 30 stacked frames of a hand motion.您看到的图片是 30 个堆叠的手部动作帧。 That's why in Images A* you see 2 blobs --> swipe from left to right and the AI doesn't detect the hand in the center.这就是为什么在图像 A* 中您会看到 2 个斑点 --> 从左向右滑动并且 AI 没有检测到中间的手。 Because the swipe isn't perfect, that's why the "blobs" are not at the same height every time.因为滑动并不完美,这就是为什么“斑点”每次都不在同一高度的原因。 Moreover, if the hand if closer to the camera you will get Image A, if it is further you will get Image A bis bis of EDIT 2 section.此外,如果手靠近相机,您将获得图像 A,如果更远,您将获得EDIT 2部分的图像 A bis bis。

EDIT 4 :编辑 4

The problem with IoU as I tried to use it regarding @Christoph Rackwitz answer is that it doesn't work in the case of Image A and Image A smaller (see EDIT 2 images).当我尝试使用 IoU 关于@Christoph Rackwitz 的答案时,IoU 的问题在于它在图像 A 和图像 A 较小的情况下不起作用(请参阅编辑 2图像)。

Intersection Over Union :联合交叉路口

图片

files = [ "A svk5g.png", "A bis aWBFd.png", "B x8214.png", "B bis b3Bdw.png" ]
ims = [cv.imread(f, cv.IMREAD_GRAYSCALE).astype(bool) for f in files]

def iou(a, b):
    return np.sum(a & b) / np.sum(a | b)

scores = np.array([[iou(a,b) for b in ims] for a in ims])
array([[1.     , 0.88364, 0.07373, 0.08069],
       [0.88364, 1.     , 0.06857, 0.06803],
       [0.07373, 0.06857, 1.     , 0.30637],
       [0.08069, 0.06803, 0.30637, 1.     ]])

So you see, 88% match between "A" and "A bis", just 30% match between "B" and "B bis", and 7-8% between A* and B*.所以你看,“A”和“A bis”之间的匹配率为 88%,“B”和“B bis”之间的匹配率仅为 30%,A* 和 B* 之间的匹配率为 7-8%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何比较两个彩色图像之间的相似性? - how to compare similarity between two color images? 在python中测量两个rgb图像之间的相似性 - measuring similarity between two rgb images in python 在Python中获得文本和集合文本之间的相似性 - Get similarity between text and the texts of a set in Python 在 Matlab/Python 中,两个图像之间的精细百分比(%)相似度指数 - Fine A Precentage(%) Similarity Index Between Two Images in Matlab/Python 如何衡量两个灰度图像之间的相似度? - How to measure the similarity between two gray level images? 根据相似性对图像进行分类 - Classify images on basics of similarity 如何使用 numpy 获得列表之间的最大相似度值? - How to get maximum similarity value between lists with numpy? 如何使用 python 获得关键字和段落之间的相似度 (PMI) 分数? - How to get similarity (PMI) score between a keyword and paragraphs using python? 2个熊猫df列之间的cosine_similarity以获得余弦距离 - cosine_similarity between 2 pandas df column to get cosine distance 是否有解决方案来获得单词列表之间的相似性评分? - Is there any solution to get score of similarity between lists of words?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM