How to move (or copy) pixels with exact color on new location?

How to move pixels with exact color on other location.
e.g. all red pixels for 10 pixels to right and for 5 pixels to up on one image.
Thanks a lot.

You can do this with a small script, for example:

  red =;
  img = IJ.getImage();
  ip = img.getProcessor();
  ip2 = ip.duplicate();
  // clear red pixels in original image
  for (i=0; i<ip.getPixelCount(); i++) {
    if (ip.get(i)==red)
  // move red pixels
  for (y=0; y<ip.getHeight(); y++) {
     for (x=0; x<ip.getWidth(); x++) {
       value = ip2.getPixel(x,y);
       if (value==red)

This can’t easily be done using the macro language because it requires working with a copy of the image.

Thanks a lot.
If someone has example how to do this with imagej macro language please welcome to share here also.