필터 지우기
필터 지우기

Can I get pdist2 results as only one value?

조회 수: 8 (최근 30일)
Queila Martins
Queila Martins 2016년 6월 3일
댓글: Queila Martins 2016년 11월 7일
Hi,
I've been using some code I wrote to calculate some distances (Euclidean, Canberra, etc). However, I did some research and I found out that using pdist2 function I could get those distances in an easier way. The problem is that pdist2 returns to me a matrix of distances, and not only one value as my code does. Is it possible to get only one value as a distance result using pdist2 function or another Matlab function? I also tried Jeffrey's distance code I found in file exchange, but I get the same (matrix of results).
Thank you in advance for your help.

채택된 답변

Image Analyst
Image Analyst 2016년 6월 6일
pdist2 gets the distances between every possible pair of points. What do you have? Just two points? If so, use hypot() or sqrt(). If you have multiple points then explain how you would like to get just one distance when there are really N*(N-1) distances.
  댓글 수: 10
Image Analyst
Image Analyst 2016년 6월 8일
Queila, the "distance" on the histogram, as if the bar tips were (x,y) coordinates like h = [2894; 0; 0; 186232], seems dumb to me and not based on any theory. Better would be what I suggested but I don't even like that - that was before I knew what you really wanted to do - I was just trying to answer your question. It depends on why you want to "compare" the two images and how you do it. For example, the SAD https://en.wikipedia.org/wiki/Sum_of_absolute_differences is a common metric. Also PSNR https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio and MSE https://en.wikipedia.org/wiki/Mean_squared_error are common and have built-in MATLAB functions for them. The SSIM https://en.wikipedia.org/wiki/Structural_similarity is a very common and popular, somewhat newer, metric.
Here's a File Exchange entry that computes 8 more.
Queila Martins
Queila Martins 2016년 6월 8일
Thank you SO much for all this information you gave me, Image Analyst. I'll check those links you've sent me and see how they apply to my problem. I'm using LBP function to get textures from an image and after this I need to compare those images to check their grade of similarity and then order them. Well, thank you very much again.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2016년 6월 3일
Pass a single point for each of the first two arguments to pdist2 and the result will be a single distance. pdist2 is optimized to return the distance from each of the points in the first argument to each of the points in the second argument, so if you only want one distance then only pass a single point to each.
  댓글 수: 6
Queila Martins
Queila Martins 2016년 6월 7일
Thanks, Walter, that makes sense. I tried what you sent and it works for a matrix with only one row. However, I tried with matrices with a lot of rows and the result is another matrix. Sorry I've been asking this, I just want to make sure I'm doing the right thing. I need to get the distance value between some images, and then I will check which one is most similar to another.
I've added two samples of images here.
Thank you
Walter Roberson
Walter Roberson 2016년 6월 8일
pdist() and pdist2() are not designed to find the distances between matrices: they are designed to find the distance between points.
You could reshape your matrix into a row vector if you wanted to get a "distance" between two of them. But note that if you do that, then the euclidean "distance" would be essentially the same thing as MSE. Euclidean would be square root of (sum of squares of differences), whereas MSE would be mean of (sum of squares of differences)

댓글을 달려면 로그인하십시오.


sergi torres
sergi torres 2016년 11월 5일
Hey Martins, did you finally find a solution? I need to do the same, find the distance (one number) of two histograms [255, 255]. Thanks!
  댓글 수: 3
Image Analyst
Image Analyst 2016년 11월 5일
Yeah, it could mean virtually nothing. I could take an image, scramble the pixels up so much that it looks just like white noise, then take the histogram and it would be the identical histogram as the original yet the image would nothing like the original. Or I could rearrange/sort the pixels to form a grayscale ramp. Again, the histogram "distance" is zero because the histogram is the same, but the image looks totally different.
Queila Martins
Queila Martins 2016년 11월 7일
Hi, Sergi
I did exactly what Walter Roberson said: I reshaped my matrix (2 histograms) into a row vector and then I used pdist formulas. The results are not the best in the world as I used LBP (Local Binary Pattern), but they are good. Now I'm gonna try GLCM and other descriptors that maybe will bring me better results.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by