diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/data/images')
8 files changed, 46 insertions, 14 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/data/images/AbstractComputeColorHistogram.java b/src/de/lmu/ifi/dbs/elki/data/images/AbstractComputeColorHistogram.java index 70d635d1..cb6ca494 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/AbstractComputeColorHistogram.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/AbstractComputeColorHistogram.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2011 + Copyright (C) 2012 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -27,30 +27,57 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException; + /** * Abstract class for color histogram computation. - * + * * @author Erich Schubert * * @apiviz.uses ImageUtil */ public abstract class AbstractComputeColorHistogram implements ComputeColorHistogram { @Override - public double[] computeColorHistogram(File file) throws IOException { + public double[] computeColorHistogram(File file, File mask) throws IOException { BufferedImage image = ImageUtil.loadImage(file); int height = image.getHeight(); int width = image.getWidth(); + + BufferedImage maski = null; + if(mask != null) { + maski = ImageUtil.loadImage(mask); + if(maski.getHeight() != height || maski.getWidth() != width) { + throw new AbortException("Input image and mask do not agree on the image size!"); + } + } + double[] bins = new double[getNumBins()]; + long valid = 0; for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) { + if(maski != null) { + int col = maski.getRGB(x, y); + // More transparent than covering + if((col >>> 24) < 127) { + continue; + } + // More black than white: (R+G+B) > 1.5 * 255 + if(((col >>> 16) & 0xFF) + ((col >>> 8) & 0xFF) + (col & 0xFF) < 382) { + continue; + } + } int bin = getBinForColor(image.getRGB(x, y)); - assert(bin < bins.length); + assert (bin < bins.length); bins[bin] += 1; + valid += 1; } } - for (int i = 0; i < bins.length; i++) { - bins[i] /= height * width; + if (valid == 0) { + throw new AbortException("Mask apparently was all-black."); + } + for(int i = 0; i < bins.length; i++) { + bins[i] /= valid; } return bins; } diff --git a/src/de/lmu/ifi/dbs/elki/data/images/BlendComposite.java b/src/de/lmu/ifi/dbs/elki/data/images/BlendComposite.java index 459a8698..e45d27bd 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/BlendComposite.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/BlendComposite.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2011 + Copyright (C) 2012 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team diff --git a/src/de/lmu/ifi/dbs/elki/data/images/ComputeColorHistogram.java b/src/de/lmu/ifi/dbs/elki/data/images/ComputeColorHistogram.java index 2c82c5bd..a13a4086 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/ComputeColorHistogram.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/ComputeColorHistogram.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2011 + Copyright (C) 2012 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -39,9 +39,14 @@ public interface ComputeColorHistogram extends Parameterizable { /** * Compute a color histogram given a file name. * + * The mask file (which may be null) is expected to use >50% transparent or + * black to mask pixels, Non-transparent white to keep pixels. Alpha values + * are not used. + * * @param file File name + * @param mask Mask file (optional) * @return Color histogram * @throws IOException on file read errors. */ - public double[] computeColorHistogram(File file) throws IOException; + public double[] computeColorHistogram(File file, File mask) throws IOException; }
\ No newline at end of file diff --git a/src/de/lmu/ifi/dbs/elki/data/images/ComputeHSBColorHistogram.java b/src/de/lmu/ifi/dbs/elki/data/images/ComputeHSBColorHistogram.java index bec59540..e5d91aa4 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/ComputeHSBColorHistogram.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/ComputeHSBColorHistogram.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2011 + Copyright (C) 2012 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team diff --git a/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveHSBColorHistogram.java b/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveHSBColorHistogram.java index ab912cff..4fb887e7 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveHSBColorHistogram.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveHSBColorHistogram.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2011 + Copyright (C) 2012 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team diff --git a/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveRGBColorHistogram.java b/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveRGBColorHistogram.java index 2032bd62..3e6e8c64 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveRGBColorHistogram.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveRGBColorHistogram.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2011 + Copyright (C) 2012 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team diff --git a/src/de/lmu/ifi/dbs/elki/data/images/ImageUtil.java b/src/de/lmu/ifi/dbs/elki/data/images/ImageUtil.java index 37079f96..10722c36 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/ImageUtil.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/ImageUtil.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2011 + Copyright (C) 2012 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team diff --git a/src/de/lmu/ifi/dbs/elki/data/images/package-info.java b/src/de/lmu/ifi/dbs/elki/data/images/package-info.java index f78b52b9..c851a21a 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/package-info.java @@ -7,7 +7,7 @@ This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures -Copyright (C) 2011 +Copyright (C) 2012 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team |