Mon, 03 Aug 2009 14:09:20 +0100
added P-touch decoder source
philpem@5 | 1 | xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
philpem@5 | 2 | <head> |
philpem@5 | 3 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta> |
philpem@5 | 4 | <title>The CImg Library - C++ Template Image Processing Toolkit</title> |
philpem@5 | 5 | <meta content="David Tschumperle" name="author"></meta> |
philpem@5 | 6 | <link rel="shortcut icon" type="image/x-icon" href="http://cimg.sourceforge.net/favicon.ico"></link> |
philpem@5 | 7 | <link rel="icon" type="image/png" href="favicon.png"></link> |
philpem@5 | 8 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
philpem@5 | 9 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
philpem@5 | 10 | <style type="text/css"> |
philpem@5 | 11 | <!-- |
philpem@5 | 12 | body {background-color:white; font-family:sans-serif; } |
philpem@5 | 13 | a:active{text-decoration:none; color:#303090} |
philpem@5 | 14 | a:link{text-decoration:none; color:#303090} |
philpem@5 | 15 | a:visited{text-decoration:none; color:#303090} |
philpem@5 | 16 | a:hover{text-decoration:underline; color:#4E9F71} |
philpem@5 | 17 | --> |
philpem@5 | 18 | </style> |
philpem@5 | 19 | <script language="JavaScript" type="text/javascript"> |
philpem@5 | 20 | <!-- Original: Eric King (eric_andrew_king@hotmail.com) is used to display images in popup windows --> |
philpem@5 | 21 | <!-- Web Site: http://redrival.com/eak/ --> |
philpem@5 | 22 | <!-- This script and many more are available free online at --> |
philpem@5 | 23 | <!-- The JavaScript Source!! http://javascript.internet.com --> |
philpem@5 | 24 | <!-- Begin |
philpem@5 | 25 | function NewWindow(mypage, myname, w, h, scroll) { |
philpem@5 | 26 | var winl = (screen.width - w) / 2; |
philpem@5 | 27 | var wint = (screen.height - h) / 2; |
philpem@5 | 28 | winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable' |
philpem@5 | 29 | win = window.open(mypage, myname, winprops) |
philpem@5 | 30 | if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); } |
philpem@5 | 31 | } |
philpem@5 | 32 | // End --> |
philpem@5 | 33 | </script> |
philpem@5 | 34 | </head> |
philpem@5 | 35 | <body> |
philpem@5 | 36 | <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"> |
philpem@5 | 37 | <tbody><tr><td> |
philpem@5 | 38 | <hr noshade="noshade" size="1" width="90%"></hr> |
philpem@5 | 39 | <center> |
philpem@5 | 40 | <br/> |
philpem@5 | 41 | <a href="http://cimg.sourceforge.net"><img src="http://cimg.sourceforge.net/img/CImgLogo.jpg" alt="" border="0"></img></a><br/> |
philpem@5 | 42 | <br/> |
philpem@5 | 43 | </center> |
philpem@5 | 44 | <hr noshade="noshade" size="1" width="90%"></hr> |
philpem@5 | 45 | <center> |
philpem@5 | 46 | <table bgcolor="#EEEEFF" style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="3" cellspacing="0"> |
philpem@5 | 47 | <tbody><tr><td style="text-align: center; vertical-align: top;"> |
philpem@5 | 48 | <font color="#FFFFFF" face="Arial,Helvetica" size="-1"> |
philpem@5 | 49 | <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/index.shtml">Main</a> <b>]</b> |
philpem@5 | 50 | <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/news.shtml">News</a><b>] </b> |
philpem@5 | 51 | <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/download.shtml">Download</a> <b>]</b> |
philpem@5 | 52 | <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/screenshots.shtml">Screenshots</a> <b>]</b> |
philpem@5 | 53 | <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/reference/group__cimg__faq.html">FAQ</a> <b>]</b> |
philpem@5 | 54 | <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/reference/group__cimg__tutorial.html">Tutorial</a> <b>]</b> |
philpem@5 | 55 | <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/reference/index.html">Documentation</a> <b>]</b> |
philpem@5 | 56 | <b>[</b> <a target="_parent" href="http://sourceforge.net/forum/forum.php?forum_id=334630">Forum</a> <b>]</b> |
philpem@5 | 57 | <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/chat.shtml">Chat</a> <b>]</b> |
philpem@5 | 58 | <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/links.shtml">Links</a> <b>]</b> |
philpem@5 | 59 | </font> |
philpem@5 | 60 | </td></tr></tbody> |
philpem@5 | 61 | </table> |
philpem@5 | 62 | </center> |
philpem@5 | 63 | <hr noshade="noshade" size="1" width="90%"></hr> |
philpem@5 | 64 | </td></tr></tbody> |
philpem@5 | 65 | </table> |
philpem@5 | 66 | <!-- Generated by Doxygen 1.5.7.1 --> |
philpem@5 | 67 | <script type="text/javascript"> |
philpem@5 | 68 | <!-- |
philpem@5 | 69 | function changeDisplayState (e){ |
philpem@5 | 70 | var num=this.id.replace(/[^[0-9]/g,''); |
philpem@5 | 71 | var button=this.firstChild; |
philpem@5 | 72 | var sectionDiv=document.getElementById('dynsection'+num); |
philpem@5 | 73 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
philpem@5 | 74 | sectionDiv.style.display='block'; |
philpem@5 | 75 | button.src='open.gif'; |
philpem@5 | 76 | }else{ |
philpem@5 | 77 | sectionDiv.style.display='none'; |
philpem@5 | 78 | button.src='closed.gif'; |
philpem@5 | 79 | } |
philpem@5 | 80 | } |
philpem@5 | 81 | function initDynSections(){ |
philpem@5 | 82 | var divs=document.getElementsByTagName('div'); |
philpem@5 | 83 | var sectionCounter=1; |
philpem@5 | 84 | for(var i=0;i<divs.length-1;i++){ |
philpem@5 | 85 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
philpem@5 | 86 | var header=divs[i]; |
philpem@5 | 87 | var section=divs[i+1]; |
philpem@5 | 88 | var button=header.firstChild; |
philpem@5 | 89 | if (button!='IMG'){ |
philpem@5 | 90 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
philpem@5 | 91 | button=document.createElement('img'); |
philpem@5 | 92 | divs[i].insertBefore(button,divs[i].firstChild); |
philpem@5 | 93 | } |
philpem@5 | 94 | header.style.cursor='pointer'; |
philpem@5 | 95 | header.onclick=changeDisplayState; |
philpem@5 | 96 | header.id='dynheader'+sectionCounter; |
philpem@5 | 97 | button.src='closed.gif'; |
philpem@5 | 98 | section.id='dynsection'+sectionCounter; |
philpem@5 | 99 | section.style.display='none'; |
philpem@5 | 100 | section.style.marginLeft='14px'; |
philpem@5 | 101 | sectionCounter++; |
philpem@5 | 102 | } |
philpem@5 | 103 | } |
philpem@5 | 104 | } |
philpem@5 | 105 | window.onload = initDynSections; |
philpem@5 | 106 | --> |
philpem@5 | 107 | </script> |
philpem@5 | 108 | <div class="navigation" id="top"> |
philpem@5 | 109 | <div class="tabs"> |
philpem@5 | 110 | <ul> |
philpem@5 | 111 | <li><a href="index.html"><span>Main Page</span></a></li> |
philpem@5 | 112 | <li><a href="modules.html"><span>Modules</span></a></li> |
philpem@5 | 113 | <li><a href="namespaces.html"><span>Namespaces</span></a></li> |
philpem@5 | 114 | <li><a href="annotated.html"><span>Classes</span></a></li> |
philpem@5 | 115 | </ul> |
philpem@5 | 116 | </div> |
philpem@5 | 117 | </div> |
philpem@5 | 118 | <div class="contents"> |
philpem@5 | 119 | <h1>Tutorial : Getting Started.</h1><table border="0" cellpadding="0" cellspacing="0"> |
philpem@5 | 120 | <tr><td></td></tr> |
philpem@5 | 121 | </table> |
philpem@5 | 122 | Let's start to write our first program to get the idea. This will demonstrate how to load and create images, as well as handle image display and mouse events. Assume we want to load a color image <code>lena.jpg</code>, smooth it, display it in a windows, and enter an event loop so that clicking a point in the image will draw the (R,G,B) intensity profiles of the corresponding image line (in another window). Yes, that sounds quite complex for a first code, but don't worry, it will be very simple using the CImg library ! Well, just look at the code below, it does the task :<p> |
philpem@5 | 123 | <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include "CImg.h"</span> |
philpem@5 | 124 | <span class="keyword">using namespace </span>cimg_library; |
philpem@5 | 125 | |
philpem@5 | 126 | <span class="keywordtype">int</span> main() { |
philpem@5 | 127 | CImg<unsigned char> image(<span class="stringliteral">"lena.jpg"</span>), visu(500,400,1,3,0); |
philpem@5 | 128 | <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 }; |
philpem@5 | 129 | image.blur(2.5); |
philpem@5 | 130 | CImgDisplay main_disp(image,<span class="stringliteral">"Click a point"</span>), draw_disp(visu,<span class="stringliteral">"Intensity profile"</span>); |
philpem@5 | 131 | <span class="keywordflow">while</span> (!main_disp.is_closed && !draw_disp.is_closed) { |
philpem@5 | 132 | main_disp.wait(); |
philpem@5 | 133 | <span class="keywordflow">if</span> (main_disp.button && main_disp.mouse_y>=0) { |
philpem@5 | 134 | <span class="keyword">const</span> <span class="keywordtype">int</span> y = main_disp.mouse_y; |
philpem@5 | 135 | visu.fill(0).draw_graph(image.get_crop(0,y,0,0,image.dimx()-1,y,0,0),red,1,1,0,255,0); |
philpem@5 | 136 | visu.draw_graph(image.get_crop(0,y,0,1,image.dimx()-1,y,0,1),green,1,1,0,255,0); |
philpem@5 | 137 | visu.draw_graph(image.get_crop(0,y,0,2,image.dimx()-1,y,0,2),blue,1,1,0,255,0).display(draw_disp); |
philpem@5 | 138 | } |
philpem@5 | 139 | } |
philpem@5 | 140 | <span class="keywordflow">return</span> 0; |
philpem@5 | 141 | } |
philpem@5 | 142 | </pre></div><p> |
philpem@5 | 143 | Here is a screenshot of the resulting program :<p> |
philpem@5 | 144 | <div align="center"> |
philpem@5 | 145 | <img src="../img/tutorial.jpg" alt="tutorial.jpg"> |
philpem@5 | 146 | </div> |
philpem@5 | 147 | <p> |
philpem@5 | 148 | And here is the detailled explanation of the source, line by line :<p> |
philpem@5 | 149 | <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include "CImg.h"</span> |
philpem@5 | 150 | </pre></div> Include the main and only header file of the CImg library. <div class="fragment"><pre class="fragment"> <span class="keyword">using namespace </span>cimg_library; |
philpem@5 | 151 | </pre></div> Use the library namespace to ease the declarations afterward. <div class="fragment"><pre class="fragment"> <span class="keywordtype">int</span> main() { |
philpem@5 | 152 | </pre></div> Definition of the main function. <div class="fragment"><pre class="fragment"> CImg<unsigned char> image(<span class="stringliteral">"lena.jpg"</span>), visu(500,400,1,3,0); |
philpem@5 | 153 | </pre></div> Creation of two instances of images of <code>unsigned</code> <code>char</code> pixels. The first image <code>image</code> is initialized by reading an image file from the disk. Here, <code>lena.jpg</code> must be in the same directory than the current program. Note that you must also have installed the <em>ImageMagick</em> package in order to be able to read JPG images. The second image <code>visu</code> is initialized as a black color image with dimension <code>dx=500</code>, <code>dy=400</code>, <code>dz=1</code> (here, it is a 2D image, not a 3D one), and <code>dv=3</code> (each pixel has 3 'vector' channels R,G,B). The last argument in the constructor defines the default value of the pixel values (here <code>0</code>, which means that <code>visu</code> will be initially black). <div class="fragment"><pre class="fragment"> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 }; |
philpem@5 | 154 | </pre></div> Definition of three different colors as array of unsigned char. This will be used to draw plots with different colors. <div class="fragment"><pre class="fragment"> image.blur(2.5); |
philpem@5 | 155 | </pre></div> Blur the image, with a gaussian blur and a standard variation of 2.5. Note that most of the CImg functions have two versions : one that acts in-place (which is the case of blur), and one that returns the result as a new image (the name of the function begins then with <code>get_</code> ). In this case, one could have also written <code>image = image.get_blur(2.5);</code> (more expensive, since it needs an additional copy operation). <div class="fragment"><pre class="fragment"> CImgDisplay main_disp(image,<span class="stringliteral">"Click a point"</span>), draw_disp(visu,<span class="stringliteral">"Intensity profile"</span>); |
philpem@5 | 156 | </pre></div> Creation of two display windows, one for the input image image, and one for the image visu which will be display intensity profiles. By default, CImg displays handles events (mouse,keyboard,..). On Windows, there is a way to create fullscreen displays. <div class="fragment"><pre class="fragment"> <span class="keywordflow">while</span> (!main_disp.is_closed && !draw_disp.is_closed) { |
philpem@5 | 157 | </pre></div> Enter the event loop, the code will exit when one of the two display windows is closed. <div class="fragment"><pre class="fragment"> main_disp.wait(); |
philpem@5 | 158 | </pre></div> Wait for an event (mouse, keyboard,..) in the display window <code>main_disp</code>. <div class="fragment"><pre class="fragment"> <span class="keywordflow">if</span> (main_disp.button && main_disp.mouse_y>=0) { |
philpem@5 | 159 | </pre></div> Test if the mouse button has been clicked on the image area. One may distinguish between the 3 different mouse buttons, but in this case it is not necessary <div class="fragment"><pre class="fragment"> <span class="keyword">const</span> <span class="keywordtype">int</span> y = main_disp.mouse_y; |
philpem@5 | 160 | </pre></div> Get the image line y-coordinate that has been clicked. <div class="fragment"><pre class="fragment"> visu.fill(0).draw_graph(image.get_crop(0,y,0,0,image.dimx()-1,y,0,0),red,1,0,256,0); |
philpem@5 | 161 | </pre></div> This line illustrates the pipeline property of most of the CImg class functions. The first function <code>fill(0)</code> simply sets all pixel values with 0 (i.e. clear the image <code>visu</code>). The interesting thing is that it returns a reference to <code>visu</code> and then, can be pipelined with the function <code>draw_graph()</code> which draws a plot in the image <code>visu</code>. The plot data are given by another image (the first argument of <code>draw_graph()</code>). In this case, the given image is the red-component of the line y of the original image, retrieved by the function <code>get_crop()</code> which returns a sub-image of the image <code>image</code>. Remember that images coordinates are 4D (x,y,z,v) and for color images, the R,G,B channels are respectively given by <code>v=0, v=1</code> and <code>v=2</code>. <div class="fragment"><pre class="fragment"> visu.draw_graph(image.get_crop(0,y,0,1,image.dimx()-1,y,0,1),green,1,0,256,0); |
philpem@5 | 162 | </pre></div> Plot the intensity profile for the green channel of the clicked line. <div class="fragment"><pre class="fragment"> visu.draw_graph(image.get_crop(0,y,0,2,image.dimx()-1,y,0,2),blue,1,0,256,0).display(draw_disp); |
philpem@5 | 163 | </pre></div> Same thing for the blue channel. Note how the function (which return a reference to <code>visu</code>) is pipelined with the function <code>display()</code> that just paints the image visu in the corresponding display window. <div class="fragment"><pre class="fragment"> ...till the end |
philpem@5 | 164 | </pre></div> I don't think you need more explanations !<p> |
philpem@5 | 165 | As you have noticed, the CImg library allows to write very small and intuitive code. Note also that this source will perfectly work on Unix and Windows systems. Take also a look to the examples provided in the CImg package ( directory <code>examples/</code> ). It will show you how CImg-based code can be surprisingly small. Moreover, there is surely one example close to what you want to do. A good start will be to look at the file <code>CImg_demo.cpp</code> which contains small and various examples of what you can do with the CImg Library. All CImg classes are used in this source, and the code can be easily modified to see what happens. </div> |
philpem@5 | 166 | <hr noshade="noshade" size="1" width="100%"> |
philpem@5 | 167 | <a href="http://sourceforge.net"> |
philpem@5 | 168 | <img src="http://sourceforge.net/sflogo.php?group_id=96492&type=3" border="0" height="37" width="125"></img> |
philpem@5 | 169 | </a> |
philpem@5 | 170 | <!-- Start of StatCounter Code --> |
philpem@5 | 171 | <script type="text/javascript" language="javascript"> |
philpem@5 | 172 | <!-- |
philpem@5 | 173 | var sc_project=895001; |
philpem@5 | 174 | var sc_invisible=1; |
philpem@5 | 175 | var sc_partition=7; |
philpem@5 | 176 | var sc_security="5ea85181"; |
philpem@5 | 177 | //--> |
philpem@5 | 178 | </script> |
philpem@5 | 179 | <script type="text/javascript" language="javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript><a href="http://www.statcounter.com/" target="_blank"><img src="http://c8.statcounter.com/counter.php?sc_project=895001&java=0&security=5ea85181&invisible=1" alt="counter stats" border="0"></a> </noscript> |
philpem@5 | 180 | <!-- End of StatCounter Code --> |
philpem@5 | 181 | </body> |
philpem@5 | 182 | </html> |