Ask Your Question
0

how to change pixel position

asked 2013-07-12 09:10:40 -0600

Salmaria gravatar image

Hi, I need to change the position of the selected pixels. that is in an image i have selected some pixels by changing the color of perticular area. so now i need to get those pixels to another position. Can you please give me an idea.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-07-12 09:35:11 -0600

Ben gravatar image

updated 2013-07-12 09:40:11 -0600

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).

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-07-12 09:10:40 -0600

Seen: 1,587 times

Last updated: Jul 12 '13