Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Firstly, if you're comfortable with C++, you should consider using <a href="http://sourceforge.net/projects/opencvlibrary/" rel="nofollow noreferrer">OpenCV 2.0</a> which does away with different data types for images and matrices (<code>IplImage*</code> and <code>CvMat*</code>) and uses one structure (<code>Mat</code>) to handle both. Apart from automatic memory management and a truckload of useful routines to handle channels, etc. and some MATLAB-esque ones as well, it's really fun to use.</p> <p>For your specific problem, you access the channels of an <code>IplImage*</code> with <code>Mat</code>, like this:</p> <pre><code> IplImage *image = cvLoadImage("lena.bmp"); Mat Lena(image); vector&lt;Mat&gt; Channels; split(Lena,Channels); namedWindow("LR",CV_WINDOW_AUTOSIZE); imshow("LR",Channels[0]); waitKey(); </code></pre> <p>Now you have the copies of each channel in the <code>vector</code> <code>Channels</code>. </p> <p>If you <em>don't</em> want to use <code>OpenCV2.0</code> and extract channels, note the following. OpenCV orders multi-channel images in the following manner:</p> <p><code>x(1,1,1) x(1,1,2) x(1,1,3) x(1,2,1) x(1,2,2) x(1,2,3) ...</code></p> <p>where <code>x(i,j,k) = an element in row i of column j in channel k</code></p> <p>Also, OpenCV <strong>pads</strong> it's images .. so don't forget to jump rows with <code>widthStep</code> which accounts for these padding gaps. And along the lines of what <a href="https://stackoverflow.com/questions/1568377/convert-rgb-iplimage-to-3-arrays/1568532#1568532">csl said</a>, increase your row pointer in the outer loop (using <code>widthStep</code>) and increment this pointer to access elements in a row.</p> <p><strong>NOTE:</strong></p> <p>Since you're using 2.0 now, you can bypass <code>IplImage*</code> with <code>Mat Lena = imread("Lena.bmp");</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload