You get an error at line 30. What does the error say? (I’m guessing seg fault or similar)
The code isn’t entirely clear to me, but it looks like your problem is that your inner loop goes from image.channels() to (exanded_image.cols - 1) * image.channels(), and then you index into new_image with (x-image.channels()) which will be out of range. I think (maybe) multipying by image.channles() is wrong in your inner loop. Also the way you index with x-1 and x + 1 might be wrong - not sure what you are trying to do there (is that to access previous pixel values? If so you probably need to have a factor of channles() in there to get to the corresponding color component of the previous / next pixel.
Also have you tried inspecting the values in the debugger. What value does y-1 have? What about x - image.channels()? Are they in range of new_image.size() ?