public void cropAndCopy( Picture sourcePicture, int startSourceRow, int endSourceRow, int startSourceCol, int endSourceCol, int startDestRow, int startDestCol) { Pixel leftPixel = null; Pixel rightPixel = null; Pixel[][] pixels = this.getPixels2D(); Color rightColor = null; Pixel[][] fromPixels = sourcePicture.getPixels2D(); Pixel[][] toPixels = this.getPixels2D(); Pixel fromPixel = null; Pixel toPixel = null; for (int fromRow = startSourceRow, toRow = endSourceRow; fromRow < fromPixels.length && toRow < toPixels.length; fromRow++, toRow++) { for (int fromCol = startSourceCol, toCol = endSourceCol; fromCol < fromPixels[0].length && toCol < toPixels[0].length; fromCol++, toCol++) { fromPixel = fromPixels[fromRow][fromCol]; toPixel = toPixels[toRow][toCol]; toPixel.setColor(fromPixel.getColor()); } } }
/** Method to set the blue to 0 */ public void zeroBlue() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { for (Pixel pixelObj : rowArray) { pixelObj.setBlue(0); } } }
public void keepOnlyBlue() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { for (Pixel pixelObj : rowArray) { pixelObj.setRed(0); pixelObj.setGreen(0); } } }
// set green 255 public void maxGreen() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { for (Pixel pixelObj : rowArray) { pixelObj.setGreen(255); } } }
public void fixUnderwater() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { for (Pixel pixelObj : rowArray) { if (pixelObj.getBlue() > 160 && pixelObj.getRed() < 25) { pixelObj.setBlue(pixelObj.getBlue() + 35); } } } }
// changes the image to a Grayscale public void Grayscale() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { for (Pixel pixelObj : rowArray) { int average = (int) pixelObj.getAverage(); pixelObj.setGreen(average); pixelObj.setBlue(average); pixelObj.setRed(average); } } }
/* ****************** CHECKLIST ****************************** [x] change the colors within the box specified by the parameters [x] the new Color in each Pixel MUST depend BOTH (a) on that particular Pixel's previous Color and (b) on the value of the amount parameter */ public boolean ManipBoxUniformly(int xMin, int yMin, int xMax, int yMax, double amount) { for (int x = xMin; x < xMax - 1; x++) { for (int y = yMin; y < yMax - 1; y++) { amount -= 0.0000001; if (amount < 0.1) amount = 0.2; Pixel p = this.getPixel(x, y); int B = (int) (p.getGreen() * (amount)); p.setGreen(B); } } return true; }
public void mirrorVerticalRightToLeft() { Pixel[][] pixels = this.getPixels2D(); Pixel leftPixel = null; Pixel rightPixel = null; int pictureWidth = pixels[0].length; for (int row = 0; row < pixels.length; row++) { for (int col = pixels[0].length - 1; col > pictureWidth / 2; col--) { rightPixel = pixels[row][col]; leftPixel = pixels[row][(pictureWidth / 2) - (col - pictureWidth / 2)]; leftPixel.setColor(rightPixel.getColor()); } } }
// implements max red to only the right side of the image public void rightRed() { Pixel[][] pixels = this.getPixels2D(); Pixel leftPixel = null; Pixel rightPixel = null; int width = pixels[0].length; for (int row = 0; row < pixels.length; row++) { for (int col = 0; col < width / 2; col++) { leftPixel = pixels[row][col]; rightPixel = pixels[row][width - 1 - col]; rightPixel.setRed(255); } } }
/** * Method that mirrors the picture around a vertical mirror in the center of the picture from left * to right */ public void mirrorVertical() { Pixel[][] pixels = this.getPixels2D(); Pixel leftPixel = null; Pixel rightPixel = null; int width = pixels[0].length; for (int row = 0; row < pixels.length; row++) { for (int col = 0; col < width / 2; col++) { leftPixel = pixels[row][col]; rightPixel = pixels[row][width - 1 - col]; rightPixel.setColor(leftPixel.getColor()); } } }
public void mirrorGull() { int mirrorPoint = 352; Pixel leftPixel = null; Pixel rightPixel = null; Pixel[][] pixels = this.getPixels2D(); for (int row = 233; row < 323; row++) { for (int col = 235; col < mirrorPoint; col++) { leftPixel = pixels[row][col]; rightPixel = pixels[row][mirrorPoint - col + mirrorPoint]; rightPixel.setColor(leftPixel.getColor()); } } }
public void mirrorHorizontalBotToTop() { Pixel[][] pixels = this.getPixels2D(); Pixel topPixel = null; Pixel bottomPixel = null; int width = pixels[0].length; for (int col = 0; col < width; col++) { for (int row = 0; row < pixels.length / 2; row++) { topPixel = pixels[row][col]; bottomPixel = pixels[(pixels.length) - 1 - row][col]; topPixel.setColor(bottomPixel.getColor()); } } }
public void mirrorArms() { int mirrorPoint = 205; Pixel leftPixel = null; Pixel rightPixel = null; Pixel[][] pixels = this.getPixels2D(); for (int row = 152; row < 200; row++) { for (int col = 92; col < mirrorPoint; col++) { leftPixel = pixels[row][col]; rightPixel = pixels[row][mirrorPoint - col + mirrorPoint]; rightPixel.setColor(leftPixel.getColor()); } } }
public void mirrorVerticalBottomToTop() { Pixel[][] pixels = this.getPixels2D(); Pixel topPixel = null; Pixel bottomPixel = null; int width = pixels[0].length; int height = pixels.length; for (int row = 0; row < pixels.length; row++) { for (int col = 0; col < width; col++) { topPixel = pixels[height - 1 - row][col]; bottomPixel = pixels[row][col]; bottomPixel.setColor(topPixel.getColor()); } } }
public void randomColor() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] row : pixels) { for (Pixel currentPixel : row) { int randomRed, randomBlue, randomGreen; randomRed = (int) (Math.random() * 256); randomBlue = (int) (Math.random() * 256); randomGreen = (int) (Math.random() * 256); currentPixel.setBlue(randomBlue); currentPixel.setRed(randomRed); currentPixel.setGreen(randomGreen); } } }
/** * copy from the passed fromPic to the specified startRow and startCol in the current picture * * @param fromPic the picture to copy from * @param startRow the start row to copy to * @param startCol the start col to copy to */ public void copy(Picture fromPic, int startRow, int startCol) { Pixel fromPixel = null; Pixel toPixel = null; Pixel[][] toPixels = this.getPixels2D(); Pixel[][] fromPixels = fromPic.getPixels2D(); for (int fromRow = 0, toRow = startRow; fromRow < fromPixels.length && toRow < toPixels.length; fromRow++, toRow++) { for (int fromCol = 0, toCol = startCol; fromCol < fromPixels[0].length && toCol < toPixels[0].length; fromCol++, toCol++) { fromPixel = fromPixels[fromRow][fromCol]; toPixel = toPixels[toRow][toCol]; toPixel.setColor(fromPixel.getColor()); } } }
/** Mirror just part of a picture of a temple */ public void mirrorTemple() { int mirrorPoint = 276; Pixel leftPixel = null; Pixel rightPixel = null; int count = 0; Pixel[][] pixels = this.getPixels2D(); // loop through the rows for (int row = 27; row < 97; row++) { // loop from 13 to just before the mirror point for (int col = 13; col < mirrorPoint; col++) { leftPixel = pixels[row][col]; rightPixel = pixels[row][mirrorPoint - col + mirrorPoint]; rightPixel.setColor(leftPixel.getColor()); } } }
public void mirrorArms() { int mirrorPoint = 298; Pixel leftPixel = null; Pixel rightPixel = null; int count = 0; Pixel[][] pixels = this.getPixels2D(); // loop through the rows for (int row = 153; row < 192; row++) { // loop from 13 to just before the mirror point for (int col = 100; col < mirrorPoint; col++) { leftPixel = pixels[row][col]; rightPixel = pixels[mirrorPoint - row][col]; rightPixel.setColor(leftPixel.getColor()); } } }
public void negate() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { for (Pixel pixelObj : rowArray) { pixelObj.setRed(255 - pixelObj.getRed()); pixelObj.setGreen(255 - pixelObj.getGreen()); pixelObj.setBlue(255 - pixelObj.getBlue()); } } }
public void grayscale() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { for (Pixel pixelObj : rowArray) { int ave = (pixelObj.getRed() + pixelObj.getGreen() + pixelObj.getBlue()) / 3; pixelObj.setBlue(ave); pixelObj.setRed(ave); pixelObj.setGreen(ave); } } }
public void negate() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { for (Pixel pixelObj : rowArray) { int a = pixelObj.getRed(); int b = pixelObj.getBlue(); int c = pixelObj.getGreen(); pixelObj.setRed(255 - a); pixelObj.setBlue(255 - b); pixelObj.setGreen(255 - c); } } }
public void copy( Picture fromPic, int fromStartRow, int fromStartCol, int toStartRow, int toStartCol, int fromEndRow, int fromEndCol) { Pixel fromPixel = null; Pixel toPixel = null; Pixel[][] toPixels = this.getPixels2D(); Pixel[][] fromPixels = fromPic.getPixels2D(); for (int fromRow = fromStartRow, toRow = toStartRow; fromRow <= fromEndRow && toRow < toPixels.length; fromRow++, toRow++) { for (int fromCol = fromStartCol, toCol = toStartCol; fromCol <= fromEndCol && toCol < toPixels.length; fromCol++, toCol++) { fromPixel = fromPixels[fromRow][fromCol]; toPixel = toPixels[toRow][toCol]; toPixel.setColor(fromPixel.getColor()); } } }
public void greyscale() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { for (Pixel pixelObj : rowArray) { int a = pixelObj.getRed(); int b = pixelObj.getBlue(); int c = pixelObj.getGreen(); int d = (a + b + c) / 3; pixelObj.setRed(d); pixelObj.setBlue(d); pixelObj.setGreen(d); } } }
/** * Method to show large changes in color * * @param edgeDist the distance for finding edges */ public void edgeDetection(int edgeDist) { Pixel leftPixel = null; Pixel rightPixel = null; Pixel[][] pixels = this.getPixels2D(); Color rightColor = null; for (int row = 0; row < pixels.length; row++) { for (int col = 0; col < pixels[0].length - 1; col++) { leftPixel = pixels[row][col]; rightPixel = pixels[row][col + 1]; rightColor = rightPixel.getColor(); if (leftPixel.colorDistance(rightColor) > edgeDist || (row + 1 > pixels.length && leftPixel.colorDistance(pixels[row + 1][col].getColor()) > edgeDist)) leftPixel.setColor(Color.BLACK); else leftPixel.setColor(Color.WHITE); } } }
/** * Method to show large changes in color * * @param edgeDist the distance for finding edges */ public void edgeDetection(int edgeDist) { Pixel leftPixel = null; Pixel rightPixel = null; Pixel[][] pixels = this.getPixels2D(); Color rightColor = null; for (int row = 0; row < pixels.length; row++) { for (int col = 0; col < pixels[0].length - 1; col++) { leftPixel = pixels[row][col]; rightPixel = pixels[row][col + 1]; rightColor = rightPixel.getColor(); if (leftPixel.colorDistance(rightColor) > edgeDist) leftPixel.setColor(Color.BLACK); else leftPixel.setColor(Color.WHITE); } } // code to improve edge detection Pixel topPixel = null; Pixel bottomPixel = null; Color bottomColor = null; for (int col = 0; col < pixels[0].length; col++) { for (int row = 0; row < pixels.length - 1; row++) { topPixel = pixels[row][col]; bottomPixel = pixels[row + 1][col]; bottomColor = bottomPixel.getColor(); if (topPixel.colorDistance(bottomColor) > edgeDist) { topPixel.setColor(Color.BLACK); } else { topPixel.setColor(Color.WHITE); } } } }
public boolean ManipBoxPattern(int xMin, int yMin, int xMax, int yMax, double amount) { int x; int y; y = yMin; while (y < yMax) { x = xMin; while (x < xMax) { Pixel p = this.getPixel(x, y); int yOffset = Math.abs(yMin - y); int xOffset = Math.abs(xMin - x); double ra = normal(x, xMin, xMax); if (ra >= 1.0) { int R = (int) (p.getRed() * amount); int G = (int) (p.getGreen() * amount); int B = (int) (255 * amount); p.setRed(R); p.setGreen(G); p.setBlue(B); p.getColor().brighter(); } else { int R = (int) (p.getRed() * amount); int G = (int) (255 * amount); int B = (int) (p.getBlue() * amount); p.setRed(R); p.setGreen(G); p.setBlue(B); } if (x % 2 == 0) { int R = (int) (255 * amount); int G = (int) (p.getGreen() * amount); int B = (int) (p.getBlue() * amount); p.setRed(R); p.setGreen(G); p.setBlue(B); } x = x + 1; } y = y + 1; } return true; }