public static void moveRoi(ImagePlus image,
			Roi roi, int dx, int dy, int slice, int speed, int mode) {

		if(roi == null) {
			IJ.error("Roi required");
			return;
		}
		ImageStack stack = image.getStack();
		Rectangle r = roi.getBounds();
		int dt = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy);
		ImageProcessor ip = stack.getProcessor(slice).duplicate();
		ip.setRoi(roi);
		ImageProcessor copy = ip.crop();
		if(mode == CUT) {
			ip.setRoi(roi);
			ip.setValue(0);
			ip.fill();
		}
		ImageProcessor ip2 = null;
		int inserted = 0;
		for(int i = 0; i < dt; i++) {
			int xt = r.x + Math.round((float)i * dx/dt);
			int yt = r.y + Math.round((float)i * dy/dt);
			ip2 = ip.duplicate();
			ip2.copyBits(copy, xt, yt,
					Blitter.COPY_ZERO_TRANSPARENT);

			if(speed < 1 || i % speed != 0)
				continue;
			stack.addSlice("", ip2, slice + inserted);
			inserted++;
		}
		// maybe the last one was not added (in case i % speed was 0)
		if(speed < 1 || dt % speed != 0)
			stack.addSlice("", ip2, slice + inserted);
	}