/** * Changes the input image. The previous distortion is thrown away only if the input * image has a different shape */ public FDistort input( ImageBase input ) { if( this.input == null || this.input.width != input.width || this.input.height != input.height ) { distorter = null; } this.input = input; inputType = input.getImageType(); return this; }
@Override public ImageType<T> getImageType() { return output.getImageType(); }
@Override public ImageType<T> getImageType() { return output.getImageType(); }
@Override public ImageType<T> getImageType() { return output.getImageType(); }
/** * All this does is set the references to the images. Nothing else is changed and its up to the * user to correctly update everything else. * * If called the first time you need to do the following * <pre> * 1) specify the interpolation method * 2) specify the transform * 3) specify the border * </pre> * * If called again and the image shape has changed you need to do the following: * <pre> * 1) Update the transform * </pre> */ public FDistort setRefs( ImageBase input, ImageBase output ) { this.input = input; this.output = output; inputType = input.getImageType(); return this; }
public static <T extends ImageBase<T>> ImageBorder<T> wrap(BorderType borderType, T image) { ImageBorder<T> ret = generic(borderType, image.getImageType()); ret.setImage(image); return ret; }
@Override public Number get(int x, int y, int band) { int value_d[] = new int[image.getImage().getImageType().numBands]; image.get(x,y,value_d); return value_d[band]; } }
public static void down(ImageBase input , int sampleWidth , ImageBase output ) { switch( input.getImageType().getFamily() ) { case GRAY: down((ImageGray)input, sampleWidth, (ImageGray)output ); return; case PLANAR: down((Planar) input, sampleWidth, (Planar)output ); return; case INTERLEAVED: throw new IllegalArgumentException("Interleaved images are not yet supported"); } throw new IllegalArgumentException("Unknown image type"); }
/** * Specifies the input and output image and sets interpolation to BILINEAR, black image border, cache is off. */ public FDistort init(ImageBase input, ImageBase output) { this.input = input; this.output = output; inputType = input.getImageType(); interp(InterpolationType.BILINEAR); border(0); cached = false; distorter = null; outputToInput = null; return this; }
/** * Applies the distortion. */ public void apply() { // see if the distortion class needs to be created again if( distorter == null ) { Class typeOut = output.getImageType().getImageClass(); switch( input.getImageType().getFamily() ) { case GRAY: distorter = FactoryDistort.distortSB(cached, (InterpolatePixelS)interp, typeOut); break; case PLANAR: distorter = FactoryDistort.distortPL(cached, (InterpolatePixelS)interp, typeOut); break; case INTERLEAVED: distorter = FactoryDistort.distortIL(cached, (InterpolatePixelMB) interp, output.getImageType()); break; default: throw new IllegalArgumentException("Unsupported image type"); } } distorter.setModel(outputToInput); distorter.apply(input,output); } }
private void addUndistorted(final String name, final Point2Transform2_F32 model) { // Set up image distort InterpolatePixel<T> interp = FactoryInterpolation. createPixel(0,255,InterpolationType.BILINEAR, BorderType.ZERO, undist.getImageType()); ImageDistort<T,T> undistorter = FactoryDistort.distort(false, interp, undist.getImageType()); undistorter.setModel(new PointToPixelTransform_F32(model)); undistorter.apply(dist,undist); final BufferedImage out = ConvertBufferedImage.convertTo(undist,null,true); // Add this rectified image SwingUtilities.invokeLater(new Runnable() { public void run() { gui.addItem(new ImagePanel(out), name); }}); }
/** * 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"); } }
/** * 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"); } }
/** * Internal function which manages images and invokes {@link #processImage}. */ private void processImageOuter( ImageBase image ) { long startTime = System.currentTimeMillis(); // this image is owned by only this process and no other. So no need to lock it while // processing processImage(image); // If an old image finished being processes after a more recent one it won't be visualized if( !visualizeOnlyMostRecent || startTime > timeOfLastUpdated ) { timeOfLastUpdated = startTime; // Copy this frame renderBitmapImage(bitmapMode,image); // Update the visualization runOnUiThread(() -> displayView.invalidate()); } // Put the image into the stack if the image type has not changed synchronized (boofImage.imageLock) { if( boofImage.imageType.isSameType(image.getImageType())) boofImage.stackImages.add(image); } }
public static <T extends ImageBase> T convertFrom(BufferedImage src , boolean orderRgb , T output ) { ImageType<T> imageType = output.getImageType(); switch( imageType.getFamily() ) { case GRAY: convertFromSingle(src, (ImageGray)output, imageType.getImageClass()); break; case PLANAR: convertFromMulti(src, (Planar) output, orderRgb, imageType.getImageClass()); break; case INTERLEAVED: convertFromInterleaved(src, (ImageInterleaved) output, orderRgb); break; default: throw new RuntimeException("Not supported yet"); } return output; }
switch( input.getImageType().getFamily() ) { case GRAY: { if (input instanceof GrayF32) {
switch (input.getImageType().getFamily()) { case GRAY: { if (input instanceof GrayF32) {
/** * Computes the min-max value for each block in the image */ protected void computeStatistics(T input, int innerWidth, int innerHeight) { int statPixelStride = stats.getImageType().getNumBands(); int indexStats = 0; for (int y = 0; y < innerHeight; y += blockHeight) { for (int x = 0; x < innerWidth; x += blockWidth, indexStats += statPixelStride) { computeBlockStatistics(x,y,blockWidth,blockHeight,indexStats,input); } // handle the case where the image's width isn't evenly divisible by the block's width if( innerWidth != input.width ) { computeBlockStatistics(innerWidth,y,input.width-innerWidth,blockHeight,indexStats,input); indexStats += statPixelStride; } } // handle the case where the image's height isn't evenly divisible by the block's height if( innerHeight != input.height ) { int y = innerHeight; int blockHeight = input.height-innerHeight; for (int x = 0; x < innerWidth; x += blockWidth, indexStats += statPixelStride) { computeBlockStatistics(x,y,blockWidth,blockHeight,indexStats,input); } if( innerWidth != input.width ) { computeBlockStatistics(innerWidth,y,input.width-innerWidth,blockHeight,indexStats,input); } } }
private void performSegmentation() { long before = System.currentTimeMillis(); alg.segment(color, pixelToRegion); long after = System.currentTimeMillis(); System.out.println("Total time "+(after-before)); int numSegments = alg.getTotalSuperpixels(); // Computes the mean color inside each region ImageType<T> type = color.getImageType(); ComputeRegionMeanColor<T> colorize = FactorySegmentationAlg.regionMeanColor(type); FastQueue<float[]> segmentColor = new ColorQueue_F32(type.getNumBands()); segmentColor.resize(numSegments); GrowQueue_I32 regionMemberCount = new GrowQueue_I32(); regionMemberCount.resize(numSegments); ImageSegmentationOps.countRegionPixels(pixelToRegion, numSegments, regionMemberCount.data); colorize.process(color,pixelToRegion,regionMemberCount,segmentColor); VisualizeRegions.regionsColor(pixelToRegion,segmentColor,outColor); VisualizeRegions.regions(pixelToRegion,segmentColor.size(),outSegments); // Make edges appear black ConvertBufferedImage.convertTo(color,outBorder,true); VisualizeRegions.regionBorders(pixelToRegion,0x000000,outBorder); }
RectifyImageOps.rectifyImage(intrinsic1, rect1_F32, BorderType.EXTENDED, distorted1.getImageType()); ImageDistort<C,C> distortRight = RectifyImageOps.rectifyImage(intrinsic2, rect2_F32, BorderType.EXTENDED, distorted2.getImageType());