• Atul

    Hi Thanks for the code but the code is giving run time error
    when I am trying to feed the destination image ,mask , and coordinates it showing me the error
    result = poisson_blend(img2,im1,desty,destx);

    • Eric

      Hi Atul,
      Try poisson_blend(img2, img1, destx, desty);
      This code used pretty old version of OpenCV, and is sort of ugly, sorry for that, maybe I’ll rewrite it if I have time…


  • Abhinav Garg


    I noticed a bug in the original code from Siddharth in the function getGradienty:

    change the loop:

    for (int i = 0; i < h; i++)


    for(int i = 0; i < h-1; i++)

    because otherwise it was showing error because it was looking for an extra row in the image which is not there.

    • Eric

      Hey Abhinav,

      Yeah I see, it must be the (i+1) part, right? And corresponding getGradientx function have (j+1) as well. Thanks for mentioning, I’ll check it.


      • Abhinav Garg

        I am not sure about the (i+1) part but I found that in lapy function as well the loop goes from 0 to (h-1) so I made it similar in getGradienty. But yes I was kind of surprised why it did not show an error while looping across columns may be it is because of (j+1).

  • Abhinav Garg

    I checked again and I am not able to understand that why it did not show any error while looping through the columns.

    • Abhinav Garg

      I wonder if it will make a difference in processing around the last row because that is critical for seamless blending. But I have checked the results are good and there are no seems after I was able to run the code successfully by changing “h” to “h-1”

      • Eric

        I’m kind of confused too, I’ll rewrite it this weekend…

  • Pingback: ()

  • Luo

    Thanks for your share, i have a small question about the Ax=b, what you gave above the code, the A matrix, you gave an example, and I can’t understand what the 10*10 A matrix is like that, the four “1” in col = 5, row = 2; col =2, row =5;col = 10, row = 7; col = 7, row = 10.why they equals “1”, I can’t understand it with your code above the matrix.Thanks.

    • Eric

      Hi Luo,

      The “1”s in that matrix represents the neighborhood relationship between two given pixels. For example, pixel number 2 and pixel number 5 are adjacent, so what happens in the matrix is, we set A(2, 5) and A(5, 2) to be 1. Another example, say pixel number 2 and 7, they are not adjacent, so both A(2, 7) and A(7, 2) is equal to 0 (since this matrix A must be a symmetric matrix, right?). The reason that the matrix A in this post looks somewhat like “diagonal” is because I occasionally set the adjacent pixels to be adjacent numbers, that’s my bad.

      • Luo

        OK,I misunderstand the meaning of adjacent(pixel(j), pixel(i)), thanks for your reply.

  • Frank Taylor

    How can i enter a picture to use this code?

    • Eric

      Hi Frank, what do you mean by enter a picture? Load an image using OpenCV? You can use imread() function.

  • abc

    Useless, use 100G + memory

  • Alex

    Totally a bear, you maniac.

    Thanks for the demo!

  • Qiliu

    Thank you for sharing, and I learned a lot from your blog.
    Now,I am doing research on Matlab,but I can’t open the web that provide the matlab code.
    Can you share the code with me? Thank you very much!