private Histogram[][] computeBlocks(Histogram[][] cells) { final int numBlocksX = 1 + (cells[0].length - cellsPerBlockX) / this.blockStepX; final int numBlocksY = 1 + (cells.length - cellsPerBlockY) / this.blockStepY; final Histogram[][] blocks = new Histogram[numBlocksY][numBlocksX]; for (int y = 0; y < numBlocksY; y++) { for (int x = 0; x < numBlocksX; x++) { final Histogram[] blockData = new Histogram[cellsPerBlockX * cellsPerBlockY]; for (int j = 0, k = 0; j < cellsPerBlockY; j++) { for (int i = 0; i < cellsPerBlockX; i++) { blockData[k++] = cells[y * blockStepY + j][x * blockStepX + i]; } } blocks[y][x] = new Histogram(blockData); } } return blocks; }
private void computeCells(WindowedHistogramExtractor binnedData, Rectangle region) { final int cellWidth = (int) (region.width / numCellsX); final int cellHeight = (int) (region.height / numCellsY); for (int j = 0, y = (int) region.y; j < numCellsY; j++, y += cellHeight) { for (int i = 0, x = (int) region.x; i < numCellsX; i++, x += cellWidth) { binnedData.computeHistogram(x, y, cellWidth, cellHeight, cells[j][i]); cells[j][i].normaliseL2(); } } } }
/** * Get the histogram (coherent followed by incoherent) as a double * vector. * * @return A {@link DoubleFV} feature vector */ public DoubleFV asDoubleFV() { final double[] d = new double[coherentHistogram.values.length + incoherentHistogram.values.length]; int i = 0; for (final double dd : coherentHistogram.asDoubleVector()) d[i++] = dd; for (final double dd : incoherentHistogram.asDoubleVector()) d[i++] = dd; return new DoubleFV(d); }
/** * Extract the PHOG feature for the specified region of the image last * analysed with {@link #analyseImage(FImage)}. * * @param rect * the region * @return the PHOG feature */ public Histogram getFeatureVector(Rectangle rect) { final QuadtreeSampler sampler = new QuadtreeSampler(rect, nlevels + 1); Histogram hist = new Histogram(0); for (final Rectangle r : sampler) { final Histogram h = histExtractor.computeHistogram(r, magnitudes); hist = hist.combine(h); } hist.normaliseL1(); return hist; }
@Override public Histogram extract(WindowedHistogramExtractor binnedData, Rectangle region, Histogram output) { final float dx = region.width / numBlocksX; final float dy = region.height / numBlocksY; final int blockSize = binnedData.getNumBins(); if (output == null || output.values.length != blockSize * numBlocksX * numBlocksY) output = new Histogram(blockSize * numBlocksX * numBlocksY); final RectangleSampler rs = new RectangleSampler(region, dx, dy, dx, dy); int block = 0; final Histogram tmp = new Histogram(blockSize); for (final Rectangle r : rs) { binnedData.computeHistogram(r, tmp); tmp.normaliseL2(); System.arraycopy(tmp.values, 0, output.values, blockSize * block, blockSize); block++; } return output; } }
@Override final void normalise(Histogram h, int blockArea) { h.normaliseL1(); } },
/** * Checks whether a shot boundary occurred between the given frame * and the previous frame, and if so, it will add a shot boundary * to the shot boundary list. * * @param frame The new frame to process. */ @Override protected double getInterframeDistance( final MBFImage frame ) { // Get the histogram for the frame. final HistogramAnalyser hp = new HistogramAnalyser( 64 ); if( frame instanceof MBFImage ) hp.analyseImage( frame.getBand(0) ); final Histogram newHisto = hp.getHistogram(); double dist = 0; // If we have a last histogram, compare against it. if( this.lastHistogram != null ) dist = newHisto.compare( this.lastHistogram, DoubleFVComparison.EUCLIDEAN ); this.lastHistogram = newHisto; return dist; } }
final Histogram f = h.getFeatureVector(r).clone();
/** * Extract the PHOG feature for the specified region of the image last * analysed with {@link #analyseImage(FImage)}. * * @param rect * the region * @return the PHOG feature */ public Histogram getFeatureVector(Rectangle rect) { final QuadtreeSampler sampler = new QuadtreeSampler(rect, nlevels + 1); Histogram hist = new Histogram(0); for (final Rectangle r : sampler) { final Histogram h = histExtractor.computeHistogram(r, magnitudes); hist = hist.combine(h); } hist.normaliseL1(); return hist; }
@Override public Histogram extract(WindowedHistogramExtractor binnedData, Rectangle region, Histogram output) { final float dx = region.width / numBlocksX; final float dy = region.height / numBlocksY; final int blockSize = binnedData.getNumBins(); if (output == null || output.values.length != blockSize * numBlocksX * numBlocksY) output = new Histogram(blockSize * numBlocksX * numBlocksY); final RectangleSampler rs = new RectangleSampler(region, dx, dy, dx, dy); int block = 0; final Histogram tmp = new Histogram(blockSize); for (final Rectangle r : rs) { binnedData.computeHistogram(r, tmp); tmp.normaliseL2(); System.arraycopy(tmp.values, 0, output.values, blockSize * block, blockSize); block++; } return output; } }
@Override final void normalise(Histogram h, int blockArea) { h.normaliseL1(); } },
/** * Checks whether a shot boundary occurred between the given frame * and the previous frame, and if so, it will add a shot boundary * to the shot boundary list. * * @param frame The new frame to process. */ @Override protected double getInterframeDistance( final MBFImage frame ) { // Get the histogram for the frame. final HistogramAnalyser hp = new HistogramAnalyser( 64 ); if( frame instanceof MBFImage ) hp.analyseImage( frame.getBand(0) ); final Histogram newHisto = hp.getHistogram(); double dist = 0; // If we have a last histogram, compare against it. if( this.lastHistogram != null ) dist = newHisto.compare( this.lastHistogram, DoubleFVComparison.EUCLIDEAN ); this.lastHistogram = newHisto; return dist; } }
final Histogram f = h.getFeatureVector(r).clone();
private Histogram[][] computeBlocks(Histogram[][] cells) { final int numBlocksX = 1 + (cells[0].length - cellsPerBlockX) / this.blockStepX; final int numBlocksY = 1 + (cells.length - cellsPerBlockY) / this.blockStepY; final Histogram[][] blocks = new Histogram[numBlocksY][numBlocksX]; for (int y = 0; y < numBlocksY; y++) { for (int x = 0; x < numBlocksX; x++) { final Histogram[] blockData = new Histogram[cellsPerBlockX * cellsPerBlockY]; for (int j = 0, k = 0; j < cellsPerBlockY; j++) { for (int i = 0; i < cellsPerBlockX; i++) { blockData[k++] = cells[y * blockStepY + j][x * blockStepX + i]; } } blocks[y][x] = new Histogram(blockData); } } return blocks; }
private Histogram[][] computeCells(WindowedHistogramExtractor binnedData, Rectangle region) { final int numCellsX = (int) ((region.width + cellWidth / 2) / cellWidth); final int numCellsY = (int) ((region.height + cellHeight / 2) / cellHeight); final Histogram[][] cells = new Histogram[numCellsY][numCellsX]; for (int j = 0, y = (int) region.y; j < numCellsY; j++, y += cellHeight) { for (int i = 0, x = (int) region.x; i < numCellsX; i++, x += cellWidth) { cells[j][i] = binnedData.computeHistogram(x, y, cellWidth, cellHeight); cells[j][i].normaliseL2(); } } return cells; } }
@Override final void normalise(Histogram h, int blockArea) { h.normaliseL1(); for (int x = 0; x < h.values.length; x++) h.values[x] = Math.sqrt(h.values[x]); } },
/** * Get the histogram (coherent followed by incoherent) as a double * vector. * * @return A {@link DoubleFV} feature vector */ public DoubleFV asDoubleFV() { final double[] d = new double[coherentHistogram.values.length + incoherentHistogram.values.length]; int i = 0; for (final double dd : coherentHistogram.asDoubleVector()) d[i++] = dd; for (final double dd : incoherentHistogram.asDoubleVector()) d[i++] = dd; return new DoubleFV(d); }
/** * Computes the Histogram for this image. The assumption is that the image * has been normalised to the range 0..1. Values greater than 1 will be * placed in the top bin. * * @param image * The image from which to extract histogram */ @Override public void analyseImage(FImage image) { this.histogram = new Histogram(nbins); for (int r = 0; r < image.height; r++) { for (int c = 0; c < image.width; c++) { int bin = (int) (image.pixels[r][c] * nbins); if (bin > (nbins - 1)) bin = nbins - 1; histogram.values[bin]++; } } }
private void computeCells(WindowedHistogramExtractor binnedData, Rectangle region) { final int cellWidth = (int) (region.width / numCellsX); final int cellHeight = (int) (region.height / numCellsY); for (int j = 0, y = (int) region.y; j < numCellsY; j++, y += cellHeight) { for (int i = 0, x = (int) region.x; i < numCellsX; i++, x += cellWidth) { binnedData.computeHistogram(x, y, cellWidth, cellHeight, cells[j][i]); cells[j][i].normaliseL2(); } } } }
@Override final void normalise(Histogram h, int blockArea) { h.normaliseL1(); for (int x = 0; x < h.values.length; x++) h.values[x] = Math.sqrt(h.values[x]); } },