/** * Method to display pixel information for the passed x and y * * @param pictureX the x value in the picture * @param pictureY the y value in the picture */ private void displayPixelInformation(int pictureX, int pictureY) { // check that this x and y are in range if (isLocationInPicture(pictureX, pictureY)) { // save the current x and y index colIndex = pictureX; rowIndex = pictureY; // get the pixel at the x and y Pixel pixel = new Pixel(picture, colIndex, rowIndex); // set the values based on the pixel colValue.setText(Integer.toString(colIndex + numberBase)); rowValue.setText(Integer.toString(rowIndex + numberBase)); rValue.setText("R: " + pixel.getRed()); gValue.setText("G: " + pixel.getGreen()); bValue.setText("B: " + pixel.getBlue()); colorPanel.setBackground(new Color(pixel.getRed(), pixel.getGreen(), pixel.getBlue())); } else { clearInformation(); } // notify the image display of the current x and y imageDisplay.setCurrentX((int) (colIndex * zoomFactor)); imageDisplay.setCurrentY((int) (rowIndex * zoomFactor)); }
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; }
/** * Method sadMatch that computes the SAD matches by translating the template image along the * search image between two images and outputs a 2d int array of the SAD matches. * * @param: template: The template image of type Picture * @param: search: The search image of type Picture * @return: sadMatches: A 2d int array of the SAD matches between both images */ public static int[][] sadMatch(Picture template, Picture search) { // Set 2d array for the template and search images int[][] templateArray = new int[template.getHeight()][template.getWidth()]; int[][] searchArray = new int[search.getHeight()][search.getWidth()]; // Get pixel array for template and search images Pixel[] templatePixels = template.getPixels(); Pixel[] searchPixels = search.getPixels(); int widthSearch = search.getWidth(); int heightSearch = search.getHeight(); int widthTemplate = template.getWidth(); int heightTemplate = template.getHeight(); // Get the red values of each pixel and move that into the correct position for (Pixel pT : templatePixels) { templateArray[pT.getY()][pT.getX()] = pT.getRed(); } for (Pixel pS : searchPixels) { searchArray[pS.getY()][pS.getX()] = pS.getRed(); } int[][] sadMatches = new int[heightSearch - heightTemplate][widthSearch - widthTemplate]; for (int i = 0; i < sadMatches.length; i++) { // go from top to bottom for (int j = 0; j < sadMatches[0].length; j++) { // go left to right at each height int[][] sadMatchLocal = new int[heightTemplate][widthTemplate]; // hold the sads in this area for (int k = 0; k < heightTemplate; k++) { // find the differences in this area for (int l = 0; l < widthTemplate; l++) { sadMatchLocal[k][l] = Math.abs(templateArray[k][l] - searchArray[i + k][j + l]); } } // compute and set the differences int sad = 0; for (int y = 0; y < sadMatchLocal.length; y++) { for (int z = 0; z < sadMatchLocal[0].length; z++) { sad += sadMatchLocal[y][z]; } // find the sad } sadMatches[i][j] = sad; // set sad } } return sadMatches; }
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); } } } }
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 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); } } }
/** * Create the color information panel * * @param labelFont the font to use for labels * @return the color information panel */ private JPanel createColorInfoPanel(Font labelFont) { // create a color info panel JPanel colorInfoPanel = new JPanel(); colorInfoPanel.setLayout(new FlowLayout()); // get the pixel at the x and y Pixel pixel = new Pixel(picture, colIndex, rowIndex); // create the labels rValue = new JLabel("R: " + pixel.getRed()); gValue = new JLabel("G: " + pixel.getGreen()); bValue = new JLabel("B: " + pixel.getBlue()); // create the sample color panel and label colorLabel = new JLabel("Color at location: "); colorPanel = new JPanel(); colorPanel.setBorder(new LineBorder(Color.black, 1)); // set the color sample to the pixel color colorPanel.setBackground(pixel.getColor()); // set the font rValue.setFont(labelFont); gValue.setFont(labelFont); bValue.setFont(labelFont); colorLabel.setFont(labelFont); colorPanel.setPreferredSize(new Dimension(25, 25)); // add items to the color information panel colorInfoPanel.add(rValue); colorInfoPanel.add(gValue); colorInfoPanel.add(bValue); colorInfoPanel.add(colorLabel); colorInfoPanel.add(colorPanel); return colorInfoPanel; }