/** * Changes the image's width and height without declaring new memory. If the internal array * is not large enough to store the new image an IllegalArgumentException is thrown. * * @param width The new width. * @param height The new height. */ @Override public void reshape(int width, int height) { if( this.width == width && this.height == height ) return; if( isSubimage() ) throw new IllegalArgumentException("Can't reshape subimage"); for( int i = 0; i < bands.length; i++ ) { bands[i].reshape(width,height); } this.startIndex = 0; this.stride = width; this.width = width; this.height = height; }
@Override public void reshape(int width, int height, int numberOfBands) { if( getNumBands() != numberOfBands ) { if( isSubimage() ) throw new RuntimeException("Can't reshape subimage"); T[] bands = (T[]) Array.newInstance(type, numberOfBands); int N = Math.min(numberOfBands, this.bands.length ); for (int i = 0; i < N; i++) { bands[i] = this.bands[i]; bands[i].reshape(width, height); } for (int i = N; i < bands.length; i++) { bands[i] = GeneralizedImageOps.createSingleBand(type, width, height); } this.startIndex = 0; this.bands = bands; this.stride = width; this.width = width; this.height = height; } else { reshape(width, height); } }
/** * 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); } }