similie 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/ext/similie.c +7 -5
- data/test/test_basic.rb +2 -2
- data/test/test_distance.rb +6 -6
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/ext/similie.c
CHANGED
@@ -52,20 +52,22 @@ int popcount(uint64_t x) {
|
|
52
52
|
return (x * h01)>>56; //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
|
53
53
|
}
|
54
54
|
|
55
|
+
#define DCT_SIZE 32
|
56
|
+
|
55
57
|
uint64_t image_phash(IplImage *img) {
|
56
58
|
uint64_t phash = 0;
|
57
59
|
int x, y;
|
58
60
|
double avg;
|
59
61
|
|
60
|
-
IplImage *small = cvCreateImage(cvSize(
|
61
|
-
IplImage *mono = cvCreateImage(cvSize(
|
62
|
+
IplImage *small = cvCreateImage(cvSize(64, 64), 8, img->nChannels);
|
63
|
+
IplImage *mono = cvCreateImage(cvSize(64, 64), 8, 1);
|
62
64
|
|
63
65
|
cvResize(img, small, CV_INTER_CUBIC);
|
64
66
|
cvCvtColor(small, mono, CV_RGB2GRAY);
|
65
67
|
|
66
|
-
CvMat *dct = cvCreateMat(
|
67
|
-
for (x = 0; x <
|
68
|
-
for (y = 0; y <
|
68
|
+
CvMat *dct = cvCreateMat(DCT_SIZE, DCT_SIZE, CV_32FC1);
|
69
|
+
for (x = 0; x < DCT_SIZE; x++) {
|
70
|
+
for (y = 0; y < DCT_SIZE; y++) {
|
69
71
|
cvSet2D(dct, x, y, cvScalarAll(cvGetMonoPixel(mono, x, y)));
|
70
72
|
}
|
71
73
|
}
|
data/test/test_basic.rb
CHANGED
@@ -12,12 +12,12 @@ describe 'Similie image load' do
|
|
12
12
|
it 'should hash image' do
|
13
13
|
img = Similie.new(File.join($testdir, 'lena1.png'))
|
14
14
|
assert img
|
15
|
-
assert_equal
|
15
|
+
assert_equal 72342380518637824, img.hash
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should hash image using class method' do
|
19
19
|
hash = Similie.phash(File.join($testdir, 'lena1.png'))
|
20
20
|
assert hash
|
21
|
-
assert_equal
|
21
|
+
assert_equal 72342380518637824, hash
|
22
22
|
end
|
23
23
|
end
|
data/test/test_distance.rb
CHANGED
@@ -4,14 +4,14 @@ describe 'Similie image distance' do
|
|
4
4
|
it 'should work for similar images' do
|
5
5
|
images = (1..5).map {|n| Similie.new(File.join($testdir, 'lena%d.png' % n ))}
|
6
6
|
|
7
|
-
assert_equal
|
8
|
-
assert_equal
|
9
|
-
assert_equal
|
10
|
-
assert_equal
|
11
|
-
assert_equal
|
7
|
+
assert_equal 2, images[0].distance(images[1])
|
8
|
+
assert_equal 3, images[1].distance(images[2])
|
9
|
+
assert_equal 2, images[2].distance(images[3])
|
10
|
+
assert_equal 3, images[0].distance(images[3])
|
11
|
+
assert_equal 18, images[3].distance(images[4])
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should work using the singleton method' do
|
15
|
-
assert_equal
|
15
|
+
assert_equal 18, Similie.distance(File.join($testdir, 'lena4.png'), File.join($testdir, 'lena5.png'))
|
16
16
|
end
|
17
17
|
end
|