@Override public int getWidth() {return image.getWidth();}
/** * Converts Bitmap image into Planar image of the appropriate type. * * @see #declareStorage(android.graphics.Bitmap, byte[]) * * @param input Input Bitmap image. * @param output Output image. If null a new one will be declared. * @param type The type of internal single band image used in the Planar image. * @param storage Byte array used for internal storage. If null it will be declared internally. * @return The converted Planar image. */ public static <T extends ImageGray> Planar<T> bitmapToMS( Bitmap input , Planar<T> output , Class<T> type , byte[] storage ) { if( output == null ) { output = new Planar<>(type, input.getWidth(), input.getHeight(), 4); } else if( output.getWidth() != input.getWidth() || output.getHeight() != input.getHeight() ) { throw new IllegalArgumentException("Image shapes are not the same"); } if( storage == null ) storage = declareStorage(input,null); input.copyPixelsToBuffer(ByteBuffer.wrap(storage)); if( type == GrayU8.class ) ImplConvertBitmap.arrayToMulti_U8(storage, input.getConfig(), (Planar)output); else if( type == GrayF32.class ) ImplConvertBitmap.arrayToMulti_F32(storage, input.getConfig(), (Planar)output); else throw new IllegalArgumentException("Unsupported BoofCV Type"); return output; }
/** * Converts Planar image into Bitmap. * * @see #declareStorage(android.graphics.Bitmap, byte[]) * * @param input Input Planar image. * @param output Output Bitmap image. * @param storage Byte array used for internal storage. If null it will be declared internally. */ public static <T extends ImageGray<T>> void planarToBitmap(Planar<T> input , Bitmap output , byte[] storage ) { if( output.getWidth() != input.getWidth() || output.getHeight() != input.getHeight() ) { throw new IllegalArgumentException("Image shapes are not the same"); } if( storage == null ) storage = declareStorage(output,null); if( input.getBandType() == GrayU8.class ) ImplConvertBitmap.planarToArray_U8((Planar)input, storage,output.getConfig()); else if( input.getBandType() == GrayF32.class ) ImplConvertBitmap.planarToArray_F32((Planar)input, storage,output.getConfig()); else throw new IllegalArgumentException("Unsupported BoofCV Type"); output.copyPixelsFromBuffer(ByteBuffer.wrap(storage)); }
/** * Converts Planar image into Bitmap. * * @see #declareStorage(android.graphics.Bitmap, byte[]) * * @param input Input Planar image. * @param output Output Bitmap image. * @param storage Byte array used for internal storage. If null it will be declared internally. */ public static <T extends ImageGray> void multiToBitmap( Planar<T> input , Bitmap output , byte[] storage ) { if( output.getWidth() != input.getWidth() || output.getHeight() != input.getHeight() ) { throw new IllegalArgumentException("Image shapes are not the same"); } if( storage == null ) storage = declareStorage(output,null); if( input.getBandType() == GrayU8.class ) ImplConvertBitmap.multiToArray_U8((Planar)input, storage,output.getConfig()); else if( input.getBandType() == GrayF32.class ) ImplConvertBitmap.multiToArray_F32((Planar)input, storage,output.getConfig()); else throw new IllegalArgumentException("Unsupported BoofCV Type"); output.copyPixelsFromBuffer(ByteBuffer.wrap(storage)); }
/** * Converts an image into a spatial tensor * * @param input BoofCV planar image * @param output Tensor * @param miniBatch Which mini-batch in the tensor should the image be written to */ public static void imageToTensor(Planar<GrayF32> input , Tensor_F32 output , int miniBatch) { if( input.isSubimage()) throw new RuntimeException("Subimages not accepted"); if( output.getDimension() != 4 ) throw new IllegalArgumentException("Output should be 4-DOF. batch + spatial (channel,height,width)"); if( output.length(1) != input.getNumBands() ) throw new IllegalArgumentException("Number of bands don't match"); if( output.length(2) != input.getHeight() ) throw new IllegalArgumentException("Spatial height doesn't match"); if( output.length(3) != input.getWidth() ) throw new IllegalArgumentException("Spatial width doesn't match"); for (int i = 0; i < input.getNumBands(); i++) { GrayF32 band = input.getBand(i); int indexOut = output.idx(miniBatch,i,0,0); int length = input.width*input.height; System.arraycopy(band.data, 0,output.d,indexOut,length); } }
if (src.getWidth() != dst.getWidth() || src.getHeight() != dst.getHeight()) { throw new IllegalArgumentException("image dimension are different");
public static Planar<GrayF32> tensorToImage( Tensor_F32 input , Planar<GrayF32> output , int miniBatch ) { if( input.getDimension() != 4 ) throw new IllegalArgumentException("Input should be 4-DOF. batch + spatial (channel,height,width)"); int bands = input.length(1); int height = input.length(2); int width = input.length(3); if( output == null ) { output = new Planar<>(GrayF32.class,width,height,bands); } else { if (input.length(1) != output.getNumBands()) throw new IllegalArgumentException("Number of bands don't match"); if (input.length(2) != output.getHeight()) throw new IllegalArgumentException("Spatial height doesn't match"); if (input.length(3) != output.getWidth()) throw new IllegalArgumentException("Spatial width doesn't match"); } for (int i = 0; i < bands; i++) { int indexIn = input.idx(miniBatch,i,0,0); GrayF32 band = output.getBand(i); int length = output.width*output.height; System.arraycopy(input.d,indexIn,band.data,0,length); } return output; } }
/** * 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<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); } } }
/** * 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); } } }
public boolean process(GrayF32 left, GrayF32 right, OverheadView<Planar<GrayF32>> overhead) { Planar<GrayF32> overheadRGB = overhead.getImage(); gray.reshape(overheadRGB.getWidth(),overheadRGB.getHeight()); ConvertImage.average(overheadRGB,gray); if( !motion2D.process(gray) ) { return false; } // take in account map units Se2_F64 a = motion2D.getFirstToCurrent(); motion.set(a); motion.T.x = a.T.x*overhead.cellSize; motion.T.y = a.T.y*overhead.cellSize; return true; }
/** * 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; } } }
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]&0xFF);