title: opencv iplimage binarization
body: <p>I have an <code>IplImage</code> and I want to binarize (without using <code>cvThreshold</code> function) it using this following code:</p>
  
  <pre><code>#include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;iostream&gt;
  
  using namespace cv;
  using namespace std;
  
  int main()
  {
      static IplImage* img ;
  
      img = cvLoadImage ("c:\\Mytest.jpg");
  
      for(int i=0;i&lt;img-&gt;height;i++)
      {
          for(int j=0;j&lt;img-&gt;width;j++)
          {
              if (img-&gt;imageData[i*img-&gt;widthStep+j]&lt;=10)
                  ((uchar *)img-&gt;imageData)[i*img-&gt;widthStep+j]=255;
              else 
                  ((uchar *)img-&gt;imageData)[i*img-&gt;widthStep+j]=0;
          }
      }
  
      cvShowImage("After",img);
      waitKey(0);
  };
  </code></pre>
  
  <p>but this code affected only part of the image, like this:</p>
  
  <p><img src="https://i.stack.imgur.com/G8DVE.png" alt="enter image description here"></p>