Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can't change a pixel's position, as every pixel has it fixed coordinates in the image raster. But you can change another pixel's color and set it to the color of another pixel:

Mat m = ... // some RGB image
Vec3b rgbColor = m.at<Vec3b>(10,10); // get the image color at pixel with coordinates (10,10)
m.at<Vec3b>(20,20) = rgbColor; // set the destination pixel's color

You can't change a pixel's position, as every pixel has it fixed coordinates in the image raster. But you can change another a pixel's color and set it to the color of another pixel:

Mat m = ... // some RGB image
Vec3b rgbColor = m.at<Vec3b>(10,10); // get the image color at pixel with coordinates (10,10)
m.at<Vec3b>(20,20) = rgbColor; // set the destination pixel's color

If you do this with multiple pixels, it will look like something moved in your image.

You can't change a pixel's position, as every pixel has it fixed coordinates in the image raster. But you can change a pixel's color and set it to the color of another pixel:

Mat m = ... // some RGB image
Vec3b rgbColor = m.at<Vec3b>(10,10); // get the image color at pixel with coordinates (10,10)
m.at<Vec3b>(20,20) = rgbColor; // set the destination pixel's color

If you do this with multiple pixels, it will look like something moved in your image.

EDIT: Actually, it will look like you copied an image region to another. For moving image regions, you have to know, which color the source pixel should be set to (e.g. default background color).