fix important bugs, which only happens when the size of the image is not dividable by number of threads per block (N =32 in the code).

Signed-off-by: ezheng <ezheng@cs.unc.edu>
This version works. And also pretty fast.

I am going to make big changes. Belief propagation would be introduced.

Signed-off-by: ezheng <ezheng@cs.unc.edu>