Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {
- int width = imagem1.getWidth();
- int height = imagem1.getHeight();
- // create new image with the width of height and height of width
- BufferedImage imagemFiltroMediana = new BufferedImage(imagem1.getWidth(),imagem1.getHeight(),BufferedImage.TYPE_INT_RGB);
- // do not use boundaries. Starts at 1
- for (int y = 1; y < height-1; y++) {
- for (int x = 1; x < width-1; x++) {
- // think the position of the vector as starting from (0,0) and
- // going as (1,0),(2,0)...
- int[] mediana = new int[9];
- mediana[0] = imagem1.getRGB(x-1, y-1);
- mediana[1] = imagem1.getRGB(x, y-1);
- mediana[2] = imagem1.getRGB(x+1, y-1);
- mediana[3] = imagem1.getRGB(x-1, y);
- mediana[4] = imagem1.getRGB(x, y); //central element
- mediana[5] = imagem1.getRGB(x+1, y);
- mediana[6] = imagem1.getRGB(x-1, y+1);
- mediana[7] = imagem1.getRGB(x, y+1);
- mediana[8] = imagem1.getRGB(x+1, y+1);
- Arrays.sort(mediana);
- int xy = 255;
- // gets the median value. As 9 is odd, gets middle position
- xy = mediana[mediana.length / 2];
- // if (mediana.length % 2 == 0) {
- // xy = (mediana[(mediana.length / 2) - 1] + mediana[mediana.length / 2]) / 2;
- // } else {
- // xy = mediana[mediana.length / 2];
- // }
- // set the new color of the central matrix pixel
- imagemFiltroMediana.setRGB(x, y, xy);
- }
- }
- imagem1 = imagemFiltroMediana;
- ImageIcon icon = new ImageIcon(imagem1);
- jLabel1.setIcon(icon);
- this.setSize(imagem1.getWidth()+75, imagem1.getHeight()+75);
- //this.imageUpdate(imagem1, ALLBITS, 0, 0, width, height);
- System.out.println("Terminou Filtro Mediana!!!");
- }//GEN-LAST:event_jMenuItem13ActionPerformed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement