private void applyScaling() { scaledImage.reshape(panel.getWidth(), panel.getHeight()); if( scaledImage.width <= 0 || scaledImage.height <= 0 ) { return; } if( latestImage.width != 0 && latestImage.height != 0 ) { new FDistort(latestImage, scaledImage).interp(interpType).border(BorderType.EXTENDED).scale().apply(); BufferedImage out = ConvertBufferedImage.convertTo(scaledImage, null, true); panel.setImageUI(out); panel.repaint(); } }
private synchronized void render( Rectangle visibleRect ) { if( visibleRect.width == 0 || visibleRect.height == 0 ) return; if( transformed.width != visibleRect.width || transformed.height != visibleRect.height || workImage == null ) { transformed.reshape(visibleRect.width,visibleRect.height); workImage = new BufferedImage(visibleRect.width,visibleRect.height,BufferedImage.TYPE_INT_RGB); } double x = -visibleRect.x; double y = -visibleRect.y; new FDistort(input,transformed).interpNN().affine(scale,0,0,scale,x,y).apply(); ConvertBufferedImage.convertTo(transformed,workImage,true); }
/** * Constructor which specifies the characteristics of the undistorted image * * @param width Width of undistorted image * @param height Height of undistorted image * @param imageType Type of undistorted image */ public RemovePerspectiveDistortion( int width , int height , ImageType<T> imageType ) { this(width,height); output = imageType.createImage(width,height); distort = new FDistort(imageType); distort.output(output); distort.interp(InterpolationType.BILINEAR).transform(transform); }
/** * 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; }
@Override public void setActiveAlgorithm(String name, Object cookie) { DisplayGaussianKernelApp.DerivType dt = (DisplayGaussianKernelApp.DerivType)cookie; // add basis SteerableKernel<K> steerable = createKernel(dt.orderX,dt.orderY); basisPanel.reset(); for( int i = 0; i < steerable.getBasisSize(); i++ ) { T smallImg = GKernelMath.convertToImage(steerable.getBasis(i)); new FDistort(smallImg,largeImg).scaleExt().interpNN().apply(); double maxValue = GImageStatistics.maxAbs(largeImg); BufferedImage out = VisualizeImageData.colorizeSign(largeImg,null,maxValue); basisPanel.addImage(out,"Basis "+i); } // add steered kernels steerPanel.reset(); for( int i = 0; i <= 20; i++ ) { double angle = Math.PI*i/20.0; K kernel = steerable.compute(angle); T smallImg = GKernelMath.convertToImage(kernel); new FDistort(smallImg,largeImg).scaleExt().interpNN().apply(); double maxValue = GImageStatistics.maxAbs(largeImg); BufferedImage out = VisualizeImageData.colorizeSign(largeImg,null,maxValue); steerPanel.addImage(out,String.format("%5d",(int)(180.0*angle/Math.PI))); } repaint(); }
private synchronized void setLevel( int level ) { // System.out.println("level "+level); if( level > 0 && ss != null ) { ImageGray small = ss.getLayer(level-1); ImageGray enlarge = GeneralizedImageOps.createSingleBand(small.getClass(), ss.getInputWidth(), ss.getInputHeight()); new FDistort(small,enlarge).interpNN().apply(); // if the size isn't the same null it so a new image will be declared if( levelImage != null && (levelImage.getWidth() != enlarge.width || levelImage.getHeight() != enlarge.height )) { levelImage = null; } levelImage = ConvertBufferedImage.convertTo(enlarge,levelImage,true); double scale = ss.getScale(level-1); levelPoints.clear(); for( ScalePoint p : points ) { if( p.scale == scale ) { levelPoints.add(p); } } } else { levelPoints.clear(); levelPoints.addAll(points); } this.activeLevel = level; }
/** * Applies distortion removal to the specified region in the input image. The undistorted image is returned. * @param input Input image * @param corner0 Top left corner * @param corner1 Top right corner * @param corner2 Bottom right corner * @param corner3 Bottom left corner * @return true if successful or false if it failed */ public boolean apply( T input , Point2D_F64 corner0 , Point2D_F64 corner1 , Point2D_F64 corner2 , Point2D_F64 corner3 ) { if( createTransform(corner0, corner1, corner2, corner3)) { distort.input(input).apply(); return true; } else { return false; } }
@Override public void initialize(int imageWidth, int imageHeight, int sensorOrientation) { binary.reshape(imageWidth, imageHeight); work.reshape(imageWidth, imageHeight); scaled.reshape(imageWidth/3,imageHeight/3); shrink = new FDistort(); }
/** * Applies a distortion which will rotate the input image by the specified amount. */ public FDistort rotate( double angleInputToOutput ) { PixelTransform2_F32 outputToInput = DistortSupport.transformRotate(input.width/2,input.height/2, output.width/2,output.height/2,(float)angleInputToOutput); return transform(outputToInput); }
/** * Sets interpolation to use nearest-neighbor */ public FDistort interpNN() { return interp(InterpolationType.NEAREST_NEIGHBOR); }
public FDistort affine( Affine2D_F64 affine ) { return affine(affine.a11,affine.a12,affine.a21,affine.a22,affine.tx,affine.ty); }
private void scaleUpLayers() { T l = pyramid.getLayer(0); if( upscale == null ) { interp = (InterpolatePixelS<T>) FactoryInterpolation.nearestNeighborPixelS(l.getClass()); upscale = (T)l.createNew(l.width,l.height); } else { upscale.reshape(l.width,l.height); } int N = pyramid.getNumLayers(); for( int i = 0; i < N; i++ ) { new FDistort(pyramid.getLayer(i),upscale).interpNN().scaleExt().apply(); BufferedImage b = ConvertBufferedImage.convertTo(upscale,null,true); if( showScales ) addImage(b,String.format("%5.2f",pyramid.getScale(i))); else addImage(b,String.format("%5.2f",pyramid.getSigma(i))); } } }
public static void main(String[] args) { BufferedImage original = UtilImageIO.loadImage(UtilIO.pathExample("simple_objects.jpg")); Planar<GrayF32> input = new Planar<>(GrayF32.class, original.getWidth(),original.getHeight(),3); ConvertBufferedImage.convertFromPlanar(original,input,true,GrayF32.class); Planar<GrayF32> output = new Planar<>(GrayF32.class, original.getWidth()/3,original.getHeight()/3,3); Planar<GrayF32> output2 = new Planar<>(GrayF32.class, original.getWidth()/3,original.getHeight()/3,3); AverageDownSampleOps.down(input, output); new FDistort(input,output2).scaleExt().apply(); BufferedImage outputFull = ConvertBufferedImage.convertTo_F32(output, null, true); BufferedImage outputFull2 = ConvertBufferedImage.convertTo_F32(output2, null, true); ShowImages.showWindow(original,"Original"); ShowImages.showWindow(outputFull,"3x small average"); ShowImages.showWindow(outputFull2,"3x small bilinear"); } }
private synchronized void setLevel( int level ) { // System.out.println("level "+level); if( level > 0 && ss != null ) { ImageGray small = (ImageGray)ss.getLayer(level-1); ImageGray enlarge = GeneralizedImageOps.createSingleBand(small.getClass(), ss.getInputWidth(), ss.getInputHeight()); new FDistort(small,enlarge).interpNN().apply(); // if the size isn't the same null it so a new image will be declared if( levelImage != null && (levelImage.getWidth() != enlarge.width || levelImage.getHeight() != enlarge.height )) { levelImage = null; } levelImage = ConvertBufferedImage.convertTo(enlarge,levelImage,true); double scale = ss.getScale(level-1); levelPoints.clear(); for( ScalePoint p : points ) { if( p.scale == scale ) { levelPoints.add(p); } } } else { levelPoints.clear(); levelPoints.addAll(points); } this.activeLevel = level; }
/** * Used to manually specify a transform. From output to input */ public FDistort transform( Point2Transform2_F32 outputToInput ) { return transform( new PointToPixelTransform_F32(outputToInput)); }
@Override public void setActiveAlgorithm(String name, Object cookie) { DerivType type = (DerivType)cookie; panel.reset(); for( int radius = 1; radius <= 40; radius += 2 ) { int maxOrder = Math.max(type.orderX,type.orderY); double sigma = FactoryKernelGaussian.sigmaForRadius(radius,maxOrder); Class typeKer1 = FactoryKernel.getKernelType(imageType,1); Kernel1D kerX = FactoryKernelGaussian.derivativeK(typeKer1,type.orderX,sigma,radius); Kernel1D kerY = FactoryKernelGaussian.derivativeK(typeKer1,type.orderY,sigma,radius); Kernel2D kernel = GKernelMath.convolve(kerY, kerX); T smallImg = GKernelMath.convertToImage(kernel); new FDistort(smallImg,largeImg).interpNN().scaleExt().apply(); double maxValue = GImageStatistics.maxAbs(largeImg); BufferedImage out = VisualizeImageData.colorizeSign(largeImg,null,maxValue); panel.addImage(out,String.format("%5d",radius)); } }