質問

The code included below calculates the Euclidean distance between two images in hsv color space and if the result is under a Threshold (here set to 0.5) the two images are similar and it will group them in one cluster.

This will be done for a group of images (video frames actually).

It worked well on a group of sample images but when I change the sample it starts to work odd, e.g the result is low for two different images and high (like 1.2) for two similar images.

For example the result for these two very similar images is relatively high: first pic and second pic when it actually should be under 0.5.

What is wrong?

In the code below, f is divided by 100 to allow comparison to values near 0.5.

Im1 = imread('1.jpeg');
Im2 = imread('2.jpeg');
hsv = rgb2hsv(Im1);
hn1 = hsv(:,:,1);
hn1=hist(hn1,16);
hn1=norm(hn1);
hsv = rgb2hsv(Im2);
hn2 = hsv(:,:,1);
hn2=hist(hn2,16);
hn2=norm(hn2);
f = norm(hn1-hn2,1)
f=f/100
役に立ちましたか?

解決

These two lines:

hn1=hist(hn1,16);
hn1=norm(hn1);

convert your 2D image into a scalar. I suspect that is not what you're interested in doing.....

EDIT:

Probably a better approach would be:

hn1 = hist(hn1(:),16) / numel(hn1(:));

but, you haven't really given us much on the math, so this is just a guess.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top