Java Utililty Methods BufferedImage Filter

List of utility methods to do BufferedImage Filter

  1. HOME
  2. Java
  3. B
  4. BufferedImage Filter

Description

The list of methods to do BufferedImage Filter are organized into topic(s).

Method

void applyFilter(BufferedImage img, BufferedImageOp filter)
apply Filter
BufferedImage fImg = filter.filter(img, null);
Graphics2D g = img.createGraphics();
g.drawImage(fImg, 0, 0, null, null);
g.dispose();
void applyFilter(BufferedImage img, ImageFilter filter)
apply Filter
FilteredImageSource src = new FilteredImageSource(img.getSource(), filter);
Image fImg = Toolkit.getDefaultToolkit().createImage(src);
Graphics2D g = img.createGraphics();
g.drawImage(fImg, 0, 0, null, null);
g.dispose();
BufferedImage applyFilter(LookupTable lookupTable, BufferedImage srcImg)
apply Filter
LookupOp lop = new LookupOp(lookupTable, null);
return lop.filter(srcImg, null);
BufferedImage filter(BufferedImage image, BufferedImageOp op)
filter
BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
op.filter(image, result);
return result;
BufferedImage filterContrast(BufferedImage img)
filter Contrast
final int[] histo = new int[256];
int x, y, i, min = 255, max = 0;
int r;
final int w = img.getWidth();
final int h = img.getHeight();
final BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
for (y = 0; y < h; y++) {
 for (x = 0; x < w; x++) {
...
BufferedImage filterDetectLines(BufferedImage img)
filter Detect Lines
int x, y;
int r, ra, rb;
final int w = img.getWidth();
final int h = img.getHeight();
final BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
for (y = 0; y < h; y++) {
 for (x = 0; x < w; x++) {
 r = new Color(img.getRGB(x, y)).getRed();
...
BufferedImage filterFillHoles(BufferedImage img)
filter Fill Holes
int x, y;
final int w = img.getWidth();
final int h = img.getHeight();
final BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
for (y = 0; y < h; y++) {
 for (x = 0; x < w; x++) {
 dst.setRGB(x, y, img.getRGB(x, y));
for (y = 0; y < h; y++) {
 for (x = 2; x < w - 2; x++) {
 int c1, c2, c3, c4, c5;
 c1 = new Color(img.getRGB(x - 2, y)).getRed();
 c2 = new Color(img.getRGB(x - 1, y)).getRed();
 c3 = new Color(img.getRGB(x, y)).getRed();
 c4 = new Color(img.getRGB(x + 1, y)).getRed();
 c5 = new Color(img.getRGB(x + 2, y)).getRed();
 if (c1 < 127 && c2 < 127 && c3 > 128 && c4 < 127) {
 c3 = (c1 + c2 + c4) / 3;
 } else if (c2 < 127 && c3 > 128 && c4 < 127 && c5 < 127) {
 c3 = (c2 + c4 + c5) / 3;
 dst.setRGB(x, y, new Color(c3, c3, c3).getRGB());
for (x = 0; x < w; x++) {
 for (y = 2; y < h - 2; y++) {
 int c1, c2, c3, c4, c5;
 c1 = new Color(img.getRGB(x, y - 2)).getRed();
 c2 = new Color(img.getRGB(x, y - 1)).getRed();
 c3 = new Color(img.getRGB(x, y)).getRed();
 c4 = new Color(img.getRGB(x, y + 1)).getRed();
 c5 = new Color(img.getRGB(x, y + 2)).getRed();
 if (c1 < 127 && c2 < 127 && c3 > 128 && c4 < 127) {
 c3 = (c1 + c2 + c4) / 3;
 } else if (c2 < 127 && c3 > 128 && c4 < 127 && c5 < 127) {
 c3 = (c2 + c4 + c5) / 3;
 dst.setRGB(x, y, new Color(c3, c3, c3).getRGB());
return dst;
BufferedImage filterImage(BufferedImageOp bufferedImageOp, BufferedImage srcImg, BufferedImage dstImg)
Entry point for image filtering operation.
return bufferedImageOp.filter(srcImg, dstImg);
BufferedImage filterMedian(BufferedImage img)
filter Median
final int MSIZE = 3;
int x, y, i, j;
int r;
final int[] val = new int[MSIZE * MSIZE];
final int w = img.getWidth();
final int h = img.getHeight();
final BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
for (y = 0; y < h; y++) {
...
BufferedImage filterScale(BufferedImage img, float ratio)
filter Scale
final int w = (int) (ratio * img.getWidth());
final int h = (int) (ratio * img.getHeight());
final BufferedImage newImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
for (int y = 0; y < h; y++) {
 for (int x = 0; x < w; x++) {
 final int rgb = img.getRGB((int) (x / ratio), (int) (y / ratio));
 newImg.setRGB(x, y, rgb);
return newImg;


AltStyle によって変換されたページ (->オリジナル) /