需要从图像的顶部、底部、右侧和左侧照亮 20 个像素,然后我需要比较像素值

Need to illuminate 20-pixels from top, bottom, right and left of an image and then I need to compare pixel values

我需要确定给定的图像是空白的还是具有相同的像素值,请查找以下代码。在这里我想设置一个公差。我不想将顶部、底部、左侧和右侧 20 个像素传递给此逻辑。请帮助!

for (String pic : Finallist) {
    BufferedImage image = ImageIO.read(new File(pic));
    final byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    final int width = image.getWidth();
    final int height = image.getHeight();
    final boolean hasAlphaChannel = image.getAlphaRaster() != null;
    boolean blankImage=true;
    int[][] result = new int[height][width];
    if (hasAlphaChannel) {
        final int pixelLength = 4;
        for (int pixel = 0, row = 0, col = 0; pixel < pixels.length; pixel += pixelLength) {
            int argb = 0;
            argb += (((int) pixels[pixel] & 0xff) << 24); // alpha
            argb += ((int) pixels[pixel + 1] & 0xff); // blue
            argb += (((int) pixels[pixel + 2] & 0xff) << 8); // green
            argb += (((int) pixels[pixel + 3] & 0xff) << 16); // red
            result[row][col] = argb;
            if(result[row][col]!=result[0][0]) {
                blankImage=false;
            }
            col++;

            if (col == width) {
                col = 0;
                row++;
            }
        }
    } else {
        final int pixelLength = 3;
        for (int pixel = 0, row = 0, col = 0; pixel < pixels.length; pixel += pixelLength) {
            int argb = 0;
            argb += -16777216; // 255 alpha
            argb += ((int) pixels[pixel] & 0xff); // blue
            argb += (((int) pixels[pixel + 1] & 0xff) << 8); // green
            argb += (((int) pixels[pixel + 2] & 0xff) << 16); // red
            result[row][col] = argb;
            if(result[row][col]!=result[0][0]) {
                blankImage=false;
            }
            col++;

            if (col == width) {
                col = 0;
                row++;
            }            
        }
    }

    if(blankImage==true) {
        try {
            System.out.println("Blank image found and its deleted");
            File f = new File(pic);
            f.delete();
        } catch(Exception e) {
            System.out.println("Exception"+e);
        }
    }else {
        FinalListWithOutBlank.add(pic);
    }
}

我想要播出所有内容!!这样我的代码性能就不会受到影响..我只想跳过那些像素来深入了解这个逻辑..

使用

将所需的感兴趣区域复制到另一个图像中
BufferedImage imageForEvaluation = image.getSubimage(x, y, width, height);

并将此图像用于您的逻辑。