title: I want to convert an image into pencil sketch in OpenCV
body: <p>I am trying to convert an image (from my hard drive) to a pencil sketch in <a href="http://en.wikipedia.org/wiki/OpenCV" rel="nofollow">OpenCV</a>. I am using Visual Studio 2010. I came to know the following steps to do this.</p>
  
  <ol>
  <li>invert the image (make negative)</li>
  <li>apply <a href="http://en.wikipedia.org/wiki/Gaussian_blur" rel="nofollow">Gaussian blur</a>.</li>
  <li>blend the above images by a linear dodge or color dodge.</li>
  </ol>
  
  <p>I have done the first 2 steps (very easy). Now I need information about how to do the linear dodge in C.</p>
  
  <p><em><sub>edited to add…</sub></em></p>
  
  <p>I have made the following code for the pencil sketch. But does it make a pencil sketch? Please see the result. How can I make it better?</p>
  
  <pre><code>int main( int argc, char** argv )
  {
      int col_1, row_1;
      uchar b_1, g_1, r_1, b_2, g_2, r_2, b_d, g_d, r_d;
  
      IplImage* img = cvLoadImage( "input file");
      IplImage* img1 = cvCreateImage( cvSize( img-&gt;width,img-&gt;height ), img-&gt;depth, img-&gt;nChannels);
      IplImage* img2 = cvCreateImage( cvSize( img-&gt;width,img-&gt;height ), img-&gt;depth, img-&gt;nChannels);
      IplImage* dst = cvCreateImage( cvSize( img-&gt;width,img-&gt;height ), img-&gt;depth, img-&gt;nChannels);
      IplImage* gray= cvCreateImage(cvGetSize(img), img-&gt;depth, 1);
  
      cvNamedWindow("Input", CV_WINDOW_AUTOSIZE );
      cvNamedWindow("Output", CV_WINDOW_AUTOSIZE );
  
      cvShowImage("Input", img );
      cvNot(img, img1);
      cvSmooth( img1, img2, CV_BLUR, 25,25,0,0);
  
      for( row_1 = 0; row_1 &lt; img1-&gt;height; row_1++ )
      {
          for ( col_1 = 0; col_1 &lt; img1-&gt;width; col_1++ )
          {
              b_1 = CV_IMAGE_ELEM( img1, uchar, row_1, col_1 * 3 );
              g_1 = CV_IMAGE_ELEM( img1, uchar, row_1, col_1 * 3 + 1 );
              r_1 = CV_IMAGE_ELEM( img1, uchar, row_1, col_1 * 3 + 2 );
  
              b_2 = CV_IMAGE_ELEM( img2, uchar, row_1, col_1 * 3 );
              g_2 = CV_IMAGE_ELEM( img2, uchar, row_1, col_1 * 3 + 1 );
              r_2 = CV_IMAGE_ELEM( img2, uchar, row_1, col_1 * 3 + 2 );
  
              b_d = b_1 + b_2;
              g_d = g_1 + g_2;
              r_d = r_1 + r_2;
  
              dst-&gt;imageData[img1-&gt;widthStep * row_1 + col_1* 3] = b_d;
              dst-&gt;imageData[img1-&gt;widthStep * row_1 + col_1 * 3 + 1] = g_d;
              dst-&gt;imageData[img1-&gt;widthStep * row_1 + col_1 * 3 + 2] = r_d;
          }
      }
      cvCvtColor(dst, gray, CV_BGR2GRAY);
      cvShowImage("Output", gray );
  
      cvWaitKey(0);
      cvReleaseImage( &amp;img );
      cvReleaseImage( &amp;gray);
      cvDestroyWindow("Input");
      cvDestroyWindow("Output");
  }
  </code></pre>