@Override public void reshape(int width, int height, int numberOfBands) { if( this.numBands != numberOfBands ) { if (isSubimage()) throw new IllegalArgumentException("Can't reshape sub-images"); this.numBands = -1; // force it to redeclare memory this.width = width; this.height = height; setNumberOfBands(numberOfBands); } else { reshape(width, 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 sub-images"); Object data = _getData(); if( Array.getLength(data) < width*height*numBands ) { ImageInterleaved<?> a = createNew(width,height); _setData(a._getData()); } this.width = width; this.height = height; this.stride = width*numBands; }
@Override public final void setNumberOfBands(int numBands) { if( this.numBands == numBands ) return; if( isSubimage() ) throw new IllegalArgumentException("Can't reshape sub-images"); this.imageType.numBands = numBands; this.numBands = numBands; this.stride = width*numBands; Object data = _getData(); if( data == null || Array.getLength(data) < width*height*numBands ) { ImageInterleaved<?> a = createNew(width,height); _setData(a._getData()); } }
/** * Sets this image equal to the specified image. Automatically resized to match the input image. * * @param orig The original image whose value is to be copied into this one */ @SuppressWarnings({"SuspiciousSystemArraycopy"}) @Override public void setTo(T orig) { if (orig.width != width || orig.height != height || orig.numBands != numBands ) reshape(orig.width,orig.height,orig.numBands); if (!orig.isSubimage() && !isSubimage()) { System.arraycopy(orig._getData(), orig.startIndex, _getData(), startIndex, stride * height); } else { int indexSrc = orig.startIndex; int indexDst = startIndex; for (int y = 0; y < height; y++) { System.arraycopy(orig._getData(), indexSrc, _getData(), indexDst, width * numBands); indexSrc += orig.stride; indexDst += stride; } } }
public static <T extends ImageInterleaved<T>>T convertFrom( IplImage input , T output ) { ImageDataType dataType = depthToBoofType(input.depth()); int numBands = input.nChannels(); int width = input.width(); int height = input.height(); if( output != null ) { if( output.isSubimage() ) throw new IllegalArgumentException("Can't handle sub-images"); if( output.getDataType() != dataType ) throw new IllegalArgumentException("Expected data type of " +dataType+" found "+output.getDataType()+" instead"); output.numBands = numBands; output.reshape(width,height); } else { output = (T)GeneralizedImageOps.createInterleaved(dataType,width,height,numBands); } switch( dataType ) { case U8: case S8: convertFrom_I(input,(InterleavedI8)output); break; case S16: convertFrom_I(input,(InterleavedS16)output); break; case S32: convertFrom_I(input,(InterleavedS32)output); break; case F32: convertFrom_I(input,(InterleavedF32)output); break; case F64: convertFrom_I(input,(InterleavedF64)output); break; default: throw new RuntimeException("Add support for type "+dataType); } return output; }
public static <T extends ImageInterleaved>T convertFrom( IplImage input , T output ) { ImageDataType dataType = depthToBoofType(input.depth()); int numBands = input.nChannels(); int width = input.width(); int height = input.height(); if( output != null ) { if( output.isSubimage() ) throw new IllegalArgumentException("Can't handle sub-images"); if( output.getDataType() != dataType ) throw new IllegalArgumentException("Expected data type of " +dataType+" found "+output.getDataType()+" instead"); output.numBands = numBands; output.reshape(width,height); } else { output = GeneralizedImageOps.createInterleaved(dataType,width,height,numBands); } switch( dataType ) { case U8: case S8: convertFrom_I(input,(InterleavedI8)output); break; case S16: convertFrom_I(input,(InterleavedS16)output); break; case S32: convertFrom_I(input,(InterleavedS32)output); break; case F32: convertFrom_I(input,(InterleavedF32)output); break; case F64: convertFrom_I(input,(InterleavedF64)output); break; default: throw new RuntimeException("Add support for type "+dataType); } return output; }