Magick++: analyze.cpp Source File

Magick++ 7.1.0

analyze.cpp
Go to the documentation of this file.
1 //
2 // Demonstrate using the 'analyze' process module to compute
3 // image statistics.
4 //
5 // Copyright Bob Friesenhahn, 2003, 2004
6 //
7 // Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
8 // dedicated to making software imaging solutions freely available.
9 //
10 // Usage: analyze file...
11 //
12
13 #include <Magick++.h>
14 #include <iostream>
15 #include <iomanip>
16 #include <list>
17 using namespace std;
18 using namespace Magick;
19 int main(int argc,char **argv)
20 {
21 if ( argc < 2 )
22 {
23 cout << "Usage: " << argv[0] << " file..." << endl;
24 exit( 1 );
25 }
26
27 // Initialize ImageMagick install location for Windows
28 InitializeMagick(*argv);
29
30 {
31 std::list<std::string> attributes;
32
33 attributes.push_back("TopLeftColor");
34 attributes.push_back("TopRightColor");
35 attributes.push_back("BottomLeftColor");
36 attributes.push_back("BottomRightColor");
37 attributes.push_back("filter:brightness:mean");
38 attributes.push_back("filter:brightness:standard-deviation");
39 attributes.push_back("filter:brightness:kurtosis");
40 attributes.push_back("filter:brightness:skewness");
41 attributes.push_back("filter:saturation:mean");
42 attributes.push_back("filter:saturation:standard-deviation");
43 attributes.push_back("filter:saturation:kurtosis");
44 attributes.push_back("filter:saturation:skewness");
45
46 char **arg = &argv[1];
47 while ( *arg )
48 {
49 string fname(*arg);
50 try {
51 cout << "File: " << fname << endl;
52 Image image( fname );
53
54 /* Analyze module does not require an argument list */
55 image.process("analyze",0,0);
56
57 list<std::string>::iterator pos = attributes.begin();
58 while(pos != attributes.end())
59 {
60 cout << " " << setw(16) << setfill(' ') << setiosflags(ios::left)
61 << *pos << " = " << image.attribute(*pos) << endl;
62 pos++;
63 }
64 }
65 catch( Exception &error_ )
66 {
67 cout << error_.what() << endl;
68 }
69 ++arg;
70 }
71 }
72
73 return 0;
74 }
Magick::Exception::what
virtual const char * what() const
Definition: Exception.cpp:58
Magick::Image::process
void process(std::string name_, const ::ssize_t argc_, const char **argv_)
Definition: Image.cpp:3960
std
STL namespace.
Magick++.h
main
int main(int argc, char **argv)
Definition: analyze.cpp:19
Magick::Exception
Definition: Exception.h:24
Magick::Image::attribute
void attribute(const std::string name_, const char *value_)
Definition: Image.cpp:1985
Magick
Definition: Blob.h:17
Magick::InitializeMagick
MagickPPExport void InitializeMagick(const char *path_)
Definition: Functions.cpp:45
Magick::Image
Definition: Image.h:55