Search code examples
copencvpixel

Read Pixel values, then compare and set to corresponding value


How can I find the difference of current pixel value and the next pixel value of a binary image and then set it to the current pixel using C and opencv?


Solution

  • 1) Check this latest OpenCV tutorial

    or

    2 ) Try using [cvGet2D][2] function and [cvSet2D][3] function.

    Here is the pseudocode:

    for i<image.width:
       for j<image.height:
           current = cvGet2D(array,j,i)
           next = cvGet2D(array,j+1,i+1)
           // set the value
           cvSet2D(array,j+1,i+1,current)
    

    Try to implement it.

    Below is an example on how to access pixel values and set pixel values to understand usage of above two functions.

    CvScalar s;
    s=cvGet2D(img,i,j);
    Int value = s.val[k];
    // setting new values
    s.val[k]=111;
    cvSet2D(img,i,j,s);