private static void resetOutOfRoi (ImageProcessor ip, int extraX, int extraY) {
        int width = ip.getWidth();
        int height = ip.getHeight();
        Rectangle roiRect = ip.getRoi();
        Rectangle temp = (Rectangle)roiRect.clone();
        temp.grow(extraX, extraY);
        Rectangle outer = temp.intersection(new Rectangle(width, height));

        float[] pixels = (float[])ip.getPixels();
        float[] snapPixels = (float[])ip.getSnapshotPixels();
        for (int y=outer.y, p=y*width+outer.x; y<roiRect.y; y++, p+=width)
            System.arraycopy(snapPixels, p, pixels, p, outer.width);
        int leftWidth = roiRect.x - outer.x;
        int rightWidth = outer.x+outer.width - (roiRect.x+roiRect.width);
        for (int y=roiRect.y; y<roiRect.y+roiRect.height; y++) {
            if (leftWidth > 0) {
                int p = outer.x + y*width;
                System.arraycopy(snapPixels, p, pixels, p, leftWidth);
            }
            if (rightWidth > 0) {
                int p = roiRect.x+roiRect.width + y*width;
                System.arraycopy(snapPixels, p, pixels, p, rightWidth);
            }
        }
        for (int y=roiRect.y+roiRect.height, p=y*width+outer.x; y<outer.y+outer.height; y++, p+=width)
            System.arraycopy(snapPixels, p, pixels, p, outer.width);

    }