📄 group__cimg__loops.html
字号:
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>The CImg Library - C++ Template Image Processing Library</title> <meta content="David Tschumperle" name="author"> <link rel="shortcut icon" type="image/x-icon" href="http://cimg.sourceforge.net/favicon.ico" /> <link rel="icon" type="image/png" href="favicon.png" /> <style type="text/css" media=screen> <!-- a:active{text-decoration:none; color:#303090} a:link{text-decoration:none; color:#303090} a:visited{text-decoration:none; color:#303090} a:hover{text-decoration:none; color:#4E9F71} --> </style> </head> <body bgcolor="#ffffff" fgcolor="#000000" alink="#ff0000" link="#0000ee" vlink="#551a8b"> <table align="center" border="0" cellpadding="0" cellspacing="0" width="1024"> <tbody> <tr> <td> <hr noshade="noshade" size="1" width="100%"> <center> <a href="http://cimg.sourceforge.net"><img src="../img/CImgLogo2.jpg" border="0"><img src="../img/CImgLogo.jpg" border="0"></a><br> <table style="width: 100%; text-align: left;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td style="vertical-align: top; text-align: right;"><font face="Arial,Helvetica"><big> <b>C++ Template Image Processing Library.</b></big></font></td> <td style="vertical-align: top; text-align: right;"> <a href="http://www.cnrs.fr/"><img src="../img/logoCNRS.gif" border="0"></a> <a href="http://www.greyc.ensicaen.fr/EquipeImage/"><img src="../img/logoGREYC.gif" border="0"></a> <a href="http://www-sop.inria.fr"><img src="../img/logoINRIA.gif" border="0"></a> </td> </tr> </tbody> </table> </center> <hr noshade="noshade" size="1" width="100%"> <center> <table style="width: 100%; text-align: left; margin-left: auto; margin-right: auto; background-color: rgb(238, 238, 255);" border="0" cellpadding="3" cellspacing="0"> <tbody> <tr> <td style="text-align: center; vertical-align: top;"> <font face="Arial,Helvetica" color="#FFFFFF" size="-1"> <b>[</b> <a target="_parent" href="../index.shtml">Introduction</a> <b>]</b>-<b>[</b> <a target="_parent" href="../news.shtml">News</a> <b>]</b>-<b>[</b> <a target="_parent" href="../download.shtml">Download</a> <b>]</b>-<b>[</b> <a target="_parent" href="../screenshots.shtml">Screenshots</a> <b>]</b>-<b>[</b> <a target="_parent" href="../reference/group__cimg__faq.html">FAQ</a> <b>]</b>-<b>[</b> <a target="_parent" href="../reference/group__cimg__tutorial.html">Tutorial</a> <b>]</b>-<b>[</b> <a target="_parent" href="../links.shtml">Links</a> <b>]</b>-<b>[</b> <a target="_parent" href="http://sourceforge.net/forum/forum.php?forum_id=334630">Forums-Eng</a> <b>]</b>-<b>[</b> <a target="_parent" href="http://sourceforge.net/forum/forum.php?forum_id=421080">Forums-Fr</a> <b>]</b>-<b>[</b> <a target="_parent" href="../reference/index.html">Reference</a> <b>]</b>-<b>[</b> <a target="_parent" href="http://sourceforge.net/projects/cimg/">SourceForge Repository</a> <b>]</b> </font></td> </tr> </tbody> </table> </center> <hr noshade="noshade" size="1" width="100%"> <noscript> </noscript> </td> </tr> </tbody> </table> </body></html><!-- Generated by Doxygen 1.5.1 --><div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> </ul></div><h1>Using Image Loops.</h1><table border="0" cellpadding="0" cellspacing="0"><tr><td></td></tr></table>The CImg Library provides different macros that define useful iterative loops over an image. Basically, it can be used to replace one or several <code>for(..)</code> instructions, but it also proposes interesting extensions to classical loops. Below is a list of all existing loop macros, classified in four different categories :<ul><li><a class="el" href="group__cimg__loops.html#lo1">Loops over the pixel buffer</a></li><li><a class="el" href="group__cimg__loops.html#lo4">Loops over image dimensions</a></li><li><a class="el" href="group__cimg__loops.html#lo5">Loops over interior regions and borders.</a></li><li><a class="el" href="group__cimg__loops.html#lo6">Loops using neighborhoods.</a></li></ul><h2><a class="anchor" name="lo1">Loops over the pixel buffer</a></h2>Loops over the pixel buffer are really basic loops that iterate a pointer on the pixel data buffer of a <code><a class="el" href="structcimg__library_1_1_c_img.html">cimg_library::CImg</a></code> image. Two macros are defined for this purpose :<p><ul><li><b>cimg_for(img,ptr,T)</b> : This macro loops over the pixel data buffer of the image <code>img</code>, using a pointer <code>T* ptr</code>, starting from the end of the buffer (last pixel) till the beginning of the buffer (first pixel).<ul><li><code>img</code> must be a (non empty) <code><a class="el" href="structcimg__library_1_1_c_img.html">cimg_library::CImg</a></code> image of pixels <code>T</code>.</li><li><code>ptr</code> is a pointer of type <code>T*</code>. This kind of loop should not appear a lot in your own source code, since this is a low-level loop and many functions of the CImg class may be used instead. Here is an example of use : <div class="fragment"><pre class="fragment"> CImg<float> img(320,200); cimg_for(img,ptr,<span class="keywordtype">float</span>) { *ptr=0; } <span class="comment">// Equivalent to 'img.fill(0);'</span></pre></div></li></ul></li></ul><p><ul><li><b>cimg_foroff(img,off)</b> : This macro loops over the pixel data buffer of the image <code>img</code>, using an offset <code></code>, starting from the beginning of the buffer (first pixel, <code>off=0</code>) till the end of the buffer (last pixel value, <code>off = img.size()-1</code>).<ul><li><code>img</code> must be a (non empty) cimg_library::CImg<T> image of pixels <code>T</code>.</li><li><code>off</code> is an inner-loop variable, only defined inside the scope of the loop.</li></ul></li></ul><p>Here is an example of use : <div class="fragment"><pre class="fragment"> CImg<float> img(320,200); cimg_foroff(img,off) { img[off]=0; } <span class="comment">// Equivalent to 'img.fill(0);'</span></pre></div><h2><a class="anchor" name="lo4">Loops over image dimensions</a></h2>The following loops are probably the most used loops in image processing programs. They allow to loop over the image along one or several dimensions, along a raster scan course. Here is the list of such loop macros for a single dimension :<ul><li><b>cimg_forX(img,x)</b> : equivalent to : <code>for (int x=0; x<img.dimx(); x++)</code>.</li><li><b>cimg_forY(img,y)</b> : equivalent to : <code>for (int y=0; y<img.dimy(); y++)</code>.</li><li><b>cimg_forZ(img,z)</b> : equivalent to : <code>for (int z=0; z<img.dimz(); z++)</code>.</li><li><b>cimg_forV(img,v)</b> : equivalent to : <code>for (int v=0; v<img.dimv(); v++)</code>.</li></ul><p>Combinations of these macros are also defined as other loop macros, allowing to loop directly over 2D, 3D or 4D images :<ul><li><b>cimg_forXY(img,x,y)</b> : equivalent to : <code>cimg_forY(img,y)</code> <code>cimg_forX(img,x)</code>.</li><li><b>cimg_forXZ(img,x,z)</b> : equivalent to : <code>cimg_forZ(img,z)</code> <code>cimg_forX(img,x)</code>.</li><li><b>cimg_forYZ(img,y,z)</b> : equivalent to : <code>cimg_forZ(img,z)</code> <code>cimg_forY(img,y)</code>.</li><li><b>cimg_forXV(img,x,v)</b> : equivalent to : <code>cimg_forV(img,v)</code> <code>cimg_forX(img,x)</code>.</li><li><b>cimg_forYV(img,y,v)</b> : equivalent to : <code>cimg_forV(img,v)</code> <code>cimg_forY(img,y)</code>.</li><li><b>cimg_forZV(img,z,v)</b> : equivalent to : <code>cimg_forV(img,v)</code> <code>cimg_forZ(img,z)</code>.</li><li><b>cimg_forXYZ(img,x,y,z)</b> : equivalent to : <code>cimg_forZ(img,z)</code> <code>cimg_forXY(img,x,y)</code>.</li><li><b>cimg_forXYV(img,x,y,v)</b> : equivalent to : <code>cimg_forV(img,v)</code> <code>cimg_forXY(img,x,y)</code>.</li><li><b>cimg_forXZV(img,x,z,v)</b> : equivalent to : <code>cimg_forV(img,v)</code> <code>cimg_forXZ(img,x,z)</code>.</li><li><b>cimg_forYZV(img,y,z,v)</b> : equivalent to : <code>cimg_forV(img,v)</code> <code>cimg_forYZ(img,y,z)</code>.</li><li><b>cimg_forXYZV(img,x,y,z,v)</b> : equivalent to : <code>cimg_forV(img,v)</code> <code>cimg_forXYZ(img,x,y,z)</code>.</li></ul><p><ul>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -