-
Notifications
You must be signed in to change notification settings - Fork 0
/
IMsimilarity.c
100 lines (76 loc) · 2.4 KB
/
IMsimilarity.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define IM7
#ifdef IM7
#include <MagickWand/MagickWand.h>
#else
#include <wand/MagickWand.h>
#endif
int main(int argc,char **argv) {
MagickWand *small_sample_wand;
MagickWand *original_wand;
MagickWand *comparison_wand;
MagickWand *tmp_wand;
int c;
int x = 48;
char filename[1024];
MetricType metric = RootMeanSquaredErrorMetric;
double similarity_threshold = 1.0;
RectangleInfo best_match_offset;
double similarity = -1;
MagickWandGenesis();
original_wand = NewMagickWand();
//$imagick->newPseudoImage(640, 480, "magick:logo");
MagickSetSize(original_wand, 640, 480);
MagickReadImage(original_wand, "magick:logo");
//$imagick->adaptiveResizeImage(100, 100, true);
MagickAdaptiveResizeImage(original_wand, 100, 75);
//$imagick->setImageAlphaChannel(Imagick::ALPHACHANNEL_DEACTIVATE);
MagickSetImageAlphaChannel(original_wand, DeactivateAlphaChannel);
small_sample_wand = CloneMagickWand(original_wand);
MagickCropImage(small_sample_wand, 25, 25, 50, 50);
MagickSetImageFormat(small_sample_wand, "png");
MagickSetImagePage(small_sample_wand, 25, 25, 0, 0);
MagickVignetteImage(small_sample_wand, 0.25, 0.75, 3, 3);
comparison_wand = MagickSimilarityImage(
original_wand,
small_sample_wand,
#ifdef IM7
metric,
similarity_threshold,
#endif
&best_match_offset,
&similarity
);
printf("Similarity is %f \n", similarity);
printf(
"Width: %d Height: %d x: %d, y: %d\n",
best_match_offset.width,
best_match_offset.height,
best_match_offset.x,
best_match_offset.y
);
MagickSetImageFormat(comparison_wand, "png");
#ifdef IM7
MagickWriteImage(comparison_wand, "./IM35_7.png");
#else
MagickWriteImage(comparison_wand, "./IM35_6.png");
#endif
//For IM7 compiled from master output is:
//Similarity is 390.000000
//For ImageMagick-6.9.2-5 output is:
//Similarity is 0.558027
MagickWandTerminus();
return (0);
}
// Both were compiled with:
//
// ./configure --with-quantum-depth=16 \
// --with-magick-plus-plus=no \
// --without-perl \
// --disable-static \
// --exec-prefix=/usr/sbin \
// --disable-hdri \
// --disable-docs \
// --disable-openmp