/** * 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 <T extends ImageGray<T>> void averageBand(Planar<T> input, T output) { if( GrayU8.class == input.getBandType() ) { PixelMath.averageBand((Planar<GrayU8>) input, (GrayU8) output); } else if( GrayS8.class == input.getBandType() ) { PixelMath.averageBand((Planar<GrayS8>) input, (GrayS8) output); } else if( GrayU16.class == input.getBandType() ) { PixelMath.averageBand((Planar<GrayU16>) input, (GrayU16) output); } else if( GrayS16.class == input.getBandType() ) { PixelMath.averageBand((Planar<GrayS16>) input, (GrayS16) output); } else if( GrayS32.class == input.getBandType() ) { PixelMath.averageBand((Planar<GrayS32>) input, (GrayS32) output); } else if( GrayS64.class == input.getBandType() ) { PixelMath.averageBand((Planar<GrayS64>) input, (GrayS64) output); } else if( GrayF32.class == input.getBandType() ) { PixelMath.averageBand((Planar<GrayF32>) input, (GrayF32) output); } else if( GrayF64.class == input.getBandType() ) { PixelMath.averageBand((Planar<GrayF64>) input, (GrayF64) output); } else { throw new IllegalArgumentException("Unknown image Type: "+input.getBandType().getSimpleName()); } } }
/** * Converts a buffered image into an image of the specified type. * * @param src Input BufferedImage which is to be converted * @param dst The image which it is being converted into * @param orderRgb If applicable, should it adjust the ordering of each color band to maintain color consistency */ public static <T extends ImageBase> void convertFrom(BufferedImage src, T dst , boolean orderRgb) { if( dst instanceof ImageGray) { ImageGray sb = (ImageGray)dst; convertFromSingle(src, sb, (Class<ImageGray>) sb.getClass()); } else if( dst instanceof Planar) { Planar ms = (Planar)dst; convertFromMulti(src,ms,orderRgb,ms.getBandType()); } else if( dst instanceof ImageInterleaved ) { convertFromInterleaved(src, (ImageInterleaved) dst, orderRgb); } else { throw new IllegalArgumentException("Unknown type " + dst.getClass().getSimpleName()); } }
/** * Computes a joint histogram for a planar image. Since it's a joint distribution the histogram * can become huge (and too sparse) if bin sizes are used that are too big. Also consider computing the * histogram independently in each band. * * @param image Input image. Not modified. * @param histogram Output for the histogram. Must be correctly configured first. */ public static<T extends ImageGray> void histogram(Planar<T> 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( image.getBandType() == GrayU8.class ) { HistogramFeatureOps.histogram_U8((Planar<GrayU8>)image, histogram); } else if( image.getBandType() == GrayF32.class ) { HistogramFeatureOps.histogram_F32((Planar<GrayF32>)image, histogram); } else { throw new IllegalArgumentException("Umage type not yet supportd"); } }
/** * 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 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)); }
Planar ms = (Planar)src; if( GrayU8.class == ms.getBandType() ) { return convertTo_U8((Planar<GrayU8>) ms, dst, orderRgb); } else if( GrayF32.class == ms.getBandType() ) { return convertTo_F32((Planar<GrayF32>) ms, dst, orderRgb); } else { throw new IllegalArgumentException("Planar type is not yet supported: "+ ms.getBandType().getSimpleName());
/** * Applies a pixel transform to a {@link Planar} image. * * @deprecated As of v0.19. Use {@link FDistort} instead * * @param input Input (source) image. * @param output Where the result of transforming the image image is written to. * @param transform The transform that is being applied to the image * @param borderType Describes how pixels outside the image border should be handled. * @param interpType Which type of pixel interpolation should be used. */ public static <Input extends ImageGray<Input>,Output extends ImageGray<Output>, M extends Planar<Input>,N extends Planar<Output>> void distortPL(M input, N output, PixelTransform2_F32 transform, BorderType borderType, InterpolationType interpType) { Class<Input> inputBandType = input.getBandType(); Class<Output> outputBandType = output.getBandType(); InterpolatePixelS<Input> interp = FactoryInterpolation.createPixelS(0, 255, interpType, borderType, inputBandType); ImageDistort<Input,Output> distorter = FactoryDistort.distortSB(false, interp, outputBandType); distorter.setModel(transform); distortPL(input,output,distorter); }
public static void rgbToGray_Weighted( ImageMultiBand rgb , ImageGray gray ) { gray.reshape(rgb.width,rgb.height); if( rgb instanceof Planar ) { Planar p = (Planar)rgb; if( p.getBandType() == GrayU8.class ) { rgbToGray_Weighted_U8(p,(GrayU8)gray);return; } else if( p.getBandType() == GrayF32.class ) { rgbToGray_Weighted_F32(p,(GrayF32)gray);return; } else if( p.getBandType() == GrayF64.class ) { rgbToGray_Weighted_F64(p,(GrayF64)gray);return; } } else if( rgb instanceof ImageInterleaved ) { if( rgb instanceof InterleavedU8 ) { rgbToGray_Weighted((InterleavedU8)rgb,(GrayU8)gray);return; } else if( rgb instanceof InterleavedF32 ) { rgbToGray_Weighted((InterleavedF32)rgb,(GrayF32)gray);return; } else if( rgb instanceof InterleavedF64 ) { rgbToGray_Weighted((InterleavedF64)rgb,(GrayF64)gray);return; } } throw new IllegalArgumentException("Unknown image type"); }
Planar ms = (Planar) output; if (ms.getBandType() == GrayU8.class) { ImplConvertYV12.yv12ToPlanarRgb_U8(data, ms); } else if (ms.getBandType() == GrayF32.class) { ImplConvertYV12.yv12ToPlanarRgb_F32(data, ms); } else {
Planar ms = (Planar) output; if (ms.getBandType() == GrayU8.class) { ConvertNV21.nv21TPlanarRgb_U8(data, width, height, ms); } else if (ms.getBandType() == GrayF32.class) { ConvertNV21.nv21ToPlanarRgb_F32(data, width, height , ms); } else {
/** * Converts a {@link Bitmap} into a BoofCV image. Type is determined at runtime. * @param input Bitmap image. * @param output Output image * @param storage Byte array used for internal storage. If null it will be declared internally. */ public static <T extends ImageBase> void bitmapToBoof( Bitmap input , T output , byte[] storage) { switch( output.getImageType().getFamily() ) { case GRAY: { if( output.getClass() == GrayF32.class ) bitmapToGray(input, (GrayF32) output, storage); else if( output.getClass() == GrayU8.class ) bitmapToGray(input,(GrayU8)output,storage); else throw new IllegalArgumentException("Unsupported BoofCV Image Type"); } break; case PLANAR: Planar pl = (Planar)output; bitmapToMS(input,pl,pl.getBandType(),storage); break; default: throw new IllegalArgumentException("Unsupported BoofCV Image Type"); } }
/** * Sets the values of each pixel equal to the pixels in the specified matrix. * Automatically resized to match the input image. * * @param orig The original image whose value is to be copied into this one */ @Override public void setTo( Planar<T> orig) { if (orig.width != width || orig.height != height) reshape(orig.width,orig.height); if( orig.getBandType() != getBandType() ) throw new IllegalArgumentException("The band type must be the same"); int N = orig.getNumBands(); if( N != getNumBands() ) { setNumberOfBands(orig.getNumBands()); } for( int i = 0; i < N; i++ ) { bands[i].setTo(orig.getBand(i)); } }
/** * Converts a {@link Bitmap} into a BoofCV image. Type is determined at runtime. * @param input Bitmap image. * @param output Output image. Automatically resized to match input shape. * @param storage Byte array used for internal storage. If null it will be declared internally. */ public static <T extends ImageBase<T>> void bitmapToBoof( Bitmap input , T output , byte[] storage) { if( BOverrideConvertAndroid.invokeBitmapToBoof(input,output,storage)) return; switch( output.getImageType().getFamily() ) { case GRAY: { if( output.getClass() == GrayF32.class ) bitmapToGray(input, (GrayF32) output, storage); else if( output.getClass() == GrayU8.class ) bitmapToGray(input,(GrayU8)output,storage); else throw new IllegalArgumentException("Unsupported BoofCV Image Type"); } break; case PLANAR: Planar pl = (Planar)output; bitmapToPlanar(input,pl,pl.getBandType(),storage); break; default: throw new IllegalArgumentException("Unsupported BoofCV Image Type"); } }
/** * Applies mean box filter to a {@link Planar} * * @param input Input image. Not modified. * @param output (Optional) Storage for output image, Can be null. Modified. * @param radius Radius of the box blur function. * @param storage (Optional) Storage for intermediate results. Same size as input image. Can be null. * @param <T> Input image type. * @return Output blurred image. */ public static <T extends ImageGray<T>> Planar<T> mean(Planar<T> input, @Nullable Planar<T> output, int radius , @Nullable T storage ) { if( storage == null ) storage = GeneralizedImageOps.createSingleBand(input.getBandType(),input.width,input.height); if( output == null ) output = input.createNew(input.width,input.height); for( int band = 0; band < input.getNumBands(); band++ ) { GBlurImageOps.mean(input.getBand(band),output.getBand(band),radius, storage); } return output; }
/** * Applies Gaussian blur to a {@link Planar} * * @param input Input image. Not modified. * @param output (Optional) Storage for output image, Can be null. Modified. * @param sigma Gaussian distribution's sigma. If ≤ 0 then will be selected based on radius. * @param radius Radius of the Gaussian blur function. If ≤ 0 then radius will be determined by sigma. * @param storage (Optional) Storage for intermediate results. Same size as input image. Can be null. * @param <T> Input image type. * @return Output blurred image. */ public static <T extends ImageGray<T>> Planar<T> gaussian(Planar<T> input, @Nullable Planar<T> output, double sigma , int radius, @Nullable T storage ) { if( storage == null ) storage = GeneralizedImageOps.createSingleBand(input.getBandType(), input.width, input.height); if( output == null ) output = input.createNew(input.width,input.height); for( int band = 0; band < input.getNumBands(); band++ ) { GBlurImageOps.gaussian(input.getBand(band),output.getBand(band),sigma,radius,storage); } return output; } }
Planar mo = (Planar) output; if (mi.getBandType() == mo.getBandType()) { mo.setTo(mi); } else {
/** * 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(Planar<T> input , T output ) { Class type = input.getBandType(); if( type == GrayU8.class ) { return (T)ConvertImage.average((Planar<GrayU8>)input,(GrayU8)output); } else if( type == GrayS8.class ) { return (T)ConvertImage.average((Planar<GrayS8>)input,(GrayS8)output); } else if( type == GrayU16.class ) { return (T)ConvertImage.average((Planar<GrayU16>)input,(GrayU16)output); } else if( type == GrayS16.class ) { return (T)ConvertImage.average((Planar<GrayS16>)input,(GrayS16)output); } else if( type == GrayS32.class ) { return (T)ConvertImage.average((Planar<GrayS32>)input,(GrayS32)output); } else if( type == GrayS64.class ) { return (T)ConvertImage.average((Planar<GrayS64>)input,(GrayS64)output); } else if( type == GrayF32.class ) { return (T)ConvertImage.average((Planar<GrayF32>)input,(GrayF32)output); } else if( type == GrayF64.class ) { return (T)ConvertImage.average((Planar<GrayF64>)input,(GrayF64)output); } else { throw new IllegalArgumentException("Unknown image type: "+type.getSimpleName()); } }
/** * Returns a new {@link Planar} which references the same internal single band images at this one. * * @param which List of bands which will comprise the new image * @return New image */ public Planar<T> partialSpectrum(int ...which ) { Planar<T> out = new Planar<>(getBandType(), which.length); out.setWidth(width); out.setHeight(height); out.setStride(stride); for (int i = 0; i < which.length; i++) { out.setBand(i,getBand(which[i])); } return out; }
T[] temp = (T[])Array.newInstance(image.getBandType(),4);
T[] temp = (T[])Array.newInstance(image.getBandType(),4);