@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 int getPixelStride() { return image.getNumBands(); }
@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; }
/** * Converts {@link ImageInterleaved} 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 ImageInterleaved<T>> void interleavedToBitmap(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.getImageType().getDataType() == ImageDataType.U8 ) ImplConvertBitmap.interleavedToArray((InterleavedU8) input, storage, output.getConfig()); else if( input.getImageType().getDataType() == ImageDataType.F32 ) ImplConvertBitmap.interleavedToArray((InterleavedF32) input, storage, output.getConfig()); else throw new IllegalArgumentException("Unsupported BoofCV Type"); output.copyPixelsFromBuffer(ByteBuffer.wrap(storage)); }
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; }
@Override public void applyOnlyInside() { float maxWidth = srcImg.getWidth()-1; float maxHeight = srcImg.getHeight()-1; for( int y = y0; y < y1; y++ ) { int indexDst = dstImg.startIndex + dstImg.stride*y + x0*dstImg.numBands; for( int x = x0; x < x1; x++ , indexDst += dstImg.numBands ) { dstToSrc.compute(x,y); if( dstToSrc.distX >= 0 && dstToSrc.distX <= maxWidth && dstToSrc.distY >= 0 && dstToSrc.distY <= maxHeight ) { interp.get(dstToSrc.distX, dstToSrc.distY, values); assign(indexDst,values); } } } }
throw new IllegalArgumentException("src is null!"); if (src.getWidth() != dst.getWidth() || src.getHeight() != dst.getHeight()) { throw new IllegalArgumentException("image dimension are different"); numBands = raster.getNumBands(); if( dst.getNumBands() != numBands ) throw new IllegalArgumentException("Expected "+numBands+" bands in dst not "+dst.getNumBands());
/** * 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; } } }
for (int i = 0; i < il.getNumBands(); i++) { GImageMiscOps.insertBand(sb, i, il); ImageGray so = (ImageGray)output; if( mb.getImageType().getDataType() != so.getDataType() ) { int w = output.width; int h = output.height; ImageGray tmp = GeneralizedImageOps.createSingleBand(mb.getImageType().getDataType(),w,h); average(mb,tmp); convert(tmp,so);
@Override public int getWidth() {return image.getWidth();}
@Override public int getHeight() {return image.getHeight();}
public void process( BufferedImage input ) { setInputImage(input); image.reshape(input.getWidth(),input.getHeight()); transform.reshape(input.getWidth(),input.getHeight()); magnitude.reshape(input.getWidth(),input.getHeight()); phase.reshape(input.getWidth(),input.getHeight()); ConvertBufferedImage.convertFrom(input, image, true); fft.forward(image,transform); GDiscreteFourierTransformOps.shiftZeroFrequency(transform,true); GDiscreteFourierTransformOps.magnitude(transform, magnitude); GDiscreteFourierTransformOps.phase(transform, phase); // Convert it to a log scale for visibility GPixelMath.log(magnitude, magnitude); SwingUtilities.invokeLater(new Runnable() { public void run() { setPreferredSize(new Dimension(image.width+50,image.height+20)); processedImage = true; }}); doRefreshAll(); }
public static GImageMultiBand wrap( ImageInterleaved image ) { switch( image.getDataType() ) { case U8: return new IL_U8((InterleavedU8)image); case S8: return new IL_S8((InterleavedS8)image); case U16: return new IL_U16((InterleavedU16)image); case S16: return new IL_S16((InterleavedS16)image); case S32: return new IL_S32((InterleavedS32)image); case S64: return new IL_S64((InterleavedS64)image); case F32: return new IL_F32((InterleavedF32)image); case F64: return new IL_F64((InterleavedF64)image); default: throw new IllegalArgumentException("Need to support more data types: "+image.getDataType()); } }
/** * Converts a {@link Planar} into a {@link ImageGray} by computing the average value of each pixel * across all the bands. * * @param input Input Planar image that is being converted. Not modified. * @param output (Optional) The single band output image. If null a new image is created. Modified. * @return Converted image. */ public static <T extends ImageGray<T>>T average(ImageInterleaved input , T output ) { ImageDataType type = input.getImageType().getDataType(); if( type == ImageDataType.U8) { return (T)ConvertImage.average((InterleavedU8)input,(GrayU8)output); } else if( type == ImageDataType.S8) { return (T)ConvertImage.average((InterleavedS8)input,(GrayS8)output); } else if( type == ImageDataType.U16 ) { return (T)ConvertImage.average((InterleavedU16)input,(GrayU16)output); } else if( type == ImageDataType.S16 ) { return (T)ConvertImage.average((InterleavedS16)input,(GrayS16)output); } else if( type == ImageDataType.S32 ) { return (T)ConvertImage.average((InterleavedS32)input,(GrayS32)output); } else if( type == ImageDataType.S64 ) { return (T)ConvertImage.average((InterleavedS64)input,(GrayS64)output); } else if( type == ImageDataType.F32 ) { return (T)ConvertImage.average((InterleavedF32)input,(GrayF32)output); } else if( type == ImageDataType.F64 ) { return (T)ConvertImage.average((InterleavedF64)input,(GrayF64)output); } else { throw new IllegalArgumentException("Unknown image type: " + type); } }
/** * Converts {@link ImageInterleaved} 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 ImageInterleaved> void interleavedToBitmap(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.getImageType().getDataType() == ImageDataType.U8 ) ImplConvertBitmap.interleavedToArray((InterleavedU8) input, storage, output.getConfig()); else if( input.getImageType().getDataType() == ImageDataType.F32 ) ImplConvertBitmap.interleavedToArray((InterleavedF32) input, storage, output.getConfig()); else throw new IllegalArgumentException("Unsupported BoofCV Type"); output.copyPixelsFromBuffer(ByteBuffer.wrap(storage)); }
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; }
@Override public void applyOnlyInside( GrayU8 mask ) { float maxWidth = srcImg.getWidth()-1; float maxHeight = srcImg.getHeight()-1; for( int y = y0; y < y1; y++ ) { int indexDst = dstImg.startIndex + dstImg.stride*y + x0*dstImg.numBands; int indexMsk = mask.startIndex + mask.stride*y + x0; for( int x = x0; x < x1; x++ , indexDst += dstImg.numBands , indexMsk++) { dstToSrc.compute(x,y); if( dstToSrc.distX >= 0 && dstToSrc.distX <= maxWidth && dstToSrc.distY >= 0 && dstToSrc.distY <= maxHeight ) { interp.get(dstToSrc.distX, dstToSrc.distY, values); assign(indexDst,values); mask.data[indexMsk] = 1; } else { mask.data[indexMsk] = 0; } } } }
@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()); } }
public static <T extends ImageInterleaved<T>> void interleavedYuvToBitmap(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.getImageType().getDataType() == ImageDataType.U8 ) { switch( output.getConfig() ) { case ARGB_8888: ImplConvertBitmap.interleavedYuvToArgb8888((InterleavedU8) input, storage); output.copyPixelsFromBuffer(ByteBuffer.wrap(storage)); return; case RGB_565: ImplConvertBitmap.interleavedYuvToRGB565((InterleavedU8) input, storage); output.copyPixelsFromBuffer(ByteBuffer.wrap(storage)); return; } } throw new IllegalArgumentException("Unsupported BoofCV Type"); }