/** * Computes the average for each pixel across all bands in the {@link Planar} image. * * @param input Planar image * @param output Gray scale image containing average pixel values */ public static void averageBand(Planar<GrayF32> input , GrayF32 output ) { final int h = input.getHeight(); final int w = input.getWidth(); GrayF32[] bands = input.bands; for (int y = 0; y < h; y++) { int indexInput = input.getStartIndex() + y * input.getStride(); int indexOutput = output.getStartIndex() + y * output.getStride(); int indexEnd = indexInput+w; // for(int x = 0; x < w; x++ ) { for (; indexInput < indexEnd; indexInput++, indexOutput++ ) { float total = 0; for( int i = 0; i < bands.length; i++ ) { total += bands[i].data[ indexInput ]; } output.data[indexOutput] = (total / bands.length); } } }
/** * Computes the average for each pixel across all bands in the {@link Planar} image. * * @param input Planar image * @param output Gray scale image containing average pixel values */ public static void averageBand(Planar<GrayS32> input , GrayS32 output ) { final int h = input.getHeight(); final int w = input.getWidth(); GrayS32[] bands = input.bands; for (int y = 0; y < h; y++) { int indexInput = input.getStartIndex() + y * input.getStride(); int indexOutput = output.getStartIndex() + y * output.getStride(); int indexEnd = indexInput+w; // for(int x = 0; x < w; x++ ) { for (; indexInput < indexEnd; indexInput++, indexOutput++ ) { int total = 0; for( int i = 0; i < bands.length; i++ ) { total += bands[i].data[ indexInput ]; } output.data[indexOutput] = (total / bands.length); } } }
/** * Computes the average for each pixel across all bands in the {@link Planar} image. * * @param input Planar image * @param output Gray scale image containing average pixel values */ public static void averageBand(Planar<GrayS8> input , GrayS8 output ) { final int h = input.getHeight(); final int w = input.getWidth(); GrayS8[] bands = input.bands; for (int y = 0; y < h; y++) { int indexInput = input.getStartIndex() + y * input.getStride(); int indexOutput = output.getStartIndex() + y * output.getStride(); int indexEnd = indexInput+w; // for(int x = 0; x < w; x++ ) { for (; indexInput < indexEnd; indexInput++, indexOutput++ ) { int total = 0; for( int i = 0; i < bands.length; i++ ) { total += bands[i].data[ indexInput ]; } output.data[indexOutput] = (byte)(total / bands.length); } } }
/** * Computes the average for each pixel across all bands in the {@link Planar} image. * * @param input Planar image * @param output Gray scale image containing average pixel values */ public static void averageBand(Planar<GrayS16> input , GrayS16 output ) { final int h = input.getHeight(); final int w = input.getWidth(); GrayS16[] bands = input.bands; for (int y = 0; y < h; y++) { int indexInput = input.getStartIndex() + y * input.getStride(); int indexOutput = output.getStartIndex() + y * output.getStride(); int indexEnd = indexInput+w; // for(int x = 0; x < w; x++ ) { for (; indexInput < indexEnd; indexInput++, indexOutput++ ) { int total = 0; for( int i = 0; i < bands.length; i++ ) { total += bands[i].data[ indexInput ]; } output.data[indexOutput] = (short)(total / bands.length); } } }
/** * Computes the average for each pixel across all bands in the {@link Planar} image. * * @param input Planar image * @param output Gray scale image containing average pixel values */ public static void averageBand(Planar<GrayS64> input , GrayS64 output ) { final int h = input.getHeight(); final int w = input.getWidth(); GrayS64[] bands = input.bands; for (int y = 0; y < h; y++) { int indexInput = input.getStartIndex() + y * input.getStride(); int indexOutput = output.getStartIndex() + y * output.getStride(); int indexEnd = indexInput+w; // for(int x = 0; x < w; x++ ) { for (; indexInput < indexEnd; indexInput++, indexOutput++ ) { long total = 0; for( int i = 0; i < bands.length; i++ ) { total += bands[i].data[ indexInput ]; } output.data[indexOutput] = (total / bands.length); } } }
/** * Computes the average for each pixel across all bands in the {@link Planar} image. * * @param input Planar image * @param output Gray scale image containing average pixel values */ public static void averageBand(Planar<GrayF64> input , GrayF64 output ) { final int h = input.getHeight(); final int w = input.getWidth(); GrayF64[] bands = input.bands; for (int y = 0; y < h; y++) { int indexInput = input.getStartIndex() + y * input.getStride(); int indexOutput = output.getStartIndex() + y * output.getStride(); int indexEnd = indexInput+w; // for(int x = 0; x < w; x++ ) { for (; indexInput < indexEnd; indexInput++, indexOutput++ ) { double total = 0; for( int i = 0; i < bands.length; i++ ) { total += bands[i].data[ indexInput ]; } output.data[indexOutput] = (total / bands.length); } } }
/** * Computes the average for each pixel across all bands in the {@link Planar} image. * * @param input Planar image * @param output Gray scale image containing average pixel values */ public static void averageBand(Planar<GrayU8> input , GrayU8 output ) { final int h = input.getHeight(); final int w = input.getWidth(); GrayU8[] bands = input.bands; for (int y = 0; y < h; y++) { int indexInput = input.getStartIndex() + y * input.getStride(); int indexOutput = output.getStartIndex() + y * output.getStride(); int indexEnd = indexInput+w; // for(int x = 0; x < w; x++ ) { for (; indexInput < indexEnd; indexInput++, indexOutput++ ) { int total = 0; for( int i = 0; i < bands.length; i++ ) { total += bands[i].data[ indexInput ]& 0xFF; } output.data[indexOutput] = (byte)(total / bands.length); } } }
/** * Computes the average for each pixel across all bands in the {@link Planar} image. * * @param input Planar image * @param output Gray scale image containing average pixel values */ public static void averageBand(Planar<GrayU16> input , GrayU16 output ) { final int h = input.getHeight(); final int w = input.getWidth(); GrayU16[] bands = input.bands; for (int y = 0; y < h; y++) { int indexInput = input.getStartIndex() + y * input.getStride(); int indexOutput = output.getStartIndex() + y * output.getStride(); int indexEnd = indexInput+w; // for(int x = 0; x < w; x++ ) { for (; indexInput < indexEnd; indexInput++, indexOutput++ ) { int total = 0; for( int i = 0; i < bands.length; i++ ) { total += bands[i].data[ indexInput ]& 0xFFFF; } output.data[indexOutput] = (short)(total / bands.length); } } }
/** * Constructs an N-D histogram from a {@link Planar} {@link GrayF32} image. * * @param image input image * @param histogram preconfigured histogram to store the output */ public static void histogram_F32(Planar<GrayF32> image , Histogram_F64 histogram ) { if (image.getNumBands() != histogram.getDimensions()) throw new IllegalArgumentException("Number of bands in the image and histogram must be the same"); if( !histogram.isRangeSet() ) throw new IllegalArgumentException("Must specify range along each dimension in histogram"); final int D = histogram.getDimensions(); int coordinate[] = new int[ D ]; histogram.fill(0); for (int y = 0; y < image.getHeight(); y++) { int imageIndex = image.getStartIndex() + y*image.getStride(); for (int x = 0; x < image.getWidth(); x++ , imageIndex++) { for (int i = 0; i < D; i++) { coordinate[i] = histogram.getDimensionIndex(i,image.getBand(i).data[imageIndex]); } int index = histogram.getIndex(coordinate); histogram.value[index] += 1; } } }
int imageIndex = image.getStartIndex() + y*image.getStride(); for (int x = 0; x < image.getWidth(); x++, imageIndex++) { for (int i = 0; i < D; i++) {