public static void fullViewLeft(int imageWidth,int imageHeight, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight ) { Point2Transform2_F32 tranLeft = new PointTransformHomography_F32(rectifyLeft); RectangleLength2D_F32 bound = DistortImageOps.boundBox_F32(imageWidth, imageHeight, new PointToPixelTransform_F32(tranLeft)); float scaleX = imageWidth/bound.width; float scaleY = imageHeight/bound.height; float scale = (float)Math.min(scaleX,scaleY); adjustUncalibrated(rectifyLeft, rectifyRight, bound, scale); }
public static void fullViewLeft(int imageWidth,int imageHeight, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight ) { Point2Transform2_F64 tranLeft = new PointTransformHomography_F64(rectifyLeft); RectangleLength2D_F64 bound = DistortImageOps.boundBox_F64(imageWidth, imageHeight, new PointToPixelTransform_F64(tranLeft)); double scaleX = imageWidth/bound.width; double scaleY = imageHeight/bound.height; double scale = Math.min(scaleX,scaleY); adjustUncalibrated(rectifyLeft, rectifyRight, bound, scale); }
/** * Rescales the input image and writes the results into the output image. The scale * factor is determined independently of the width and height. * @param input Input image. Not modified. * @param output Rescaled input image. Modified. * @param borderType Describes how pixels outside the image border should be handled. * @param interpType Which interpolation algorithm should be used. */ @Deprecated public static <T extends ImageBase<T>> void scale(T input, T output, BorderType borderType, InterpolationType interpType) { PixelTransformAffine_F32 model = DistortSupport.transformScale(output, input, null); if( input instanceof ImageGray) { distortSingle((ImageGray) input, (ImageGray) output, model, interpType, borderType); } else if( input instanceof Planar) { distortPL((Planar) input, (Planar) output, model, borderType, interpType); } }
/** * 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); }
@Override public void process(T input) { super.initialize(input.width,input.height); if( isSaveOriginalReference() ) throw new IllegalArgumentException("The original reference cannot be saved"); for( int i = 0; i < scale.length; i++ ) { T prev = i == 0 ? input : getLayer(i-1); T layer = getLayer(i); PixelTransformAffine_F32 model = DistortSupport.transformScale(layer,prev, null); DistortImageOps.distortSingle(prev,layer, true, model,interpolate); } }
/** * Finds an axis-aligned bounding box which would contain a image after it has been transformed. * The returned bounding box can be larger then the original image. * * @param srcWidth Width of the source image * @param srcHeight Height of the source image * @param transform Transform being applied to the image * @return Bounding box */ public static RectangleLength2D_F32 boundBox_F32( int srcWidth , int srcHeight , PixelTransform2_F32 transform ) { ImageRectangle_F32 r=new ImageRectangle_F32(); r.x0=r.y0=Float.MAX_VALUE; r.x1=r.y1=-Float.MAX_VALUE; for( int y = 0; y < srcHeight; y++ ) { transform.compute(0, y); updateBoundBox(transform, r); transform.compute(srcWidth, y); updateBoundBox(transform, r); } for( int x = 0; x < srcWidth; x++ ) { transform.compute(x, 0); updateBoundBox(transform, r); transform.compute(x, srcHeight); updateBoundBox(transform, r); } return new RectangleLength2D_F32(r.x0,r.y0,r.x1-r.x0,r.y1-r.y0); }
/** * Finds an axis-aligned bounding box which would contain a image after it has been transformed. * A sanity check is done to made sure it is contained inside the destination image's bounds. * If it is totally outside then a rectangle with negative width or height is returned. * * @param srcWidth Width of the source image * @param srcHeight Height of the source image * @param dstWidth Width of the destination image * @param dstHeight Height of the destination image * @param transform Transform being applied to the image * @return Bounding box */ public static RectangleLength2D_I32 boundBox( int srcWidth , int srcHeight , int dstWidth , int dstHeight , PixelTransform2_F32 transform ) { RectangleLength2D_I32 ret = boundBox(srcWidth,srcHeight,transform); int x0 = ret.x0; int y0 = ret.y0; int x1 = ret.x0 + ret.width; int y1 = ret.y0 + ret.height; if( x0 < 0 ) x0 = 0; if( x1 > dstWidth) x1 = dstWidth; if( y0 < 0 ) y0 = 0; if( y1 > dstHeight) y1 = dstHeight; return new RectangleLength2D_I32(x0,y0,x1-x0,y1-y0); }
private void addRectified( final String name , final DMatrixRMaj rect1 , final DMatrixRMaj rect2 ) { FMatrixRMaj rect1_F32 = new FMatrixRMaj(3,3); // TODO simplify code some how FMatrixRMaj rect2_F32 = new FMatrixRMaj(3,3); ConvertMatrixData.convert(rect1, rect1_F32); ConvertMatrixData.convert(rect2, rect2_F32); // Will rectify the image ImageType<GrayF32> imageType = ImageType.single(GrayF32.class); ImageDistort<GrayF32,GrayF32> imageDistortLeft = RectifyImageOps.rectifyImage(param.getLeft(), rect1_F32, BorderType.ZERO, imageType); ImageDistort<GrayF32,GrayF32> imageDistortRight = RectifyImageOps.rectifyImage(param.getRight(), rect2_F32, BorderType.ZERO, imageType); // Fill the image with all black GImageMiscOps.fill(rectLeft, 0); GImageMiscOps.fill(rectRight,0); // Render the rectified image DistortImageOps.distortPL(distLeft, rectLeft, imageDistortLeft); DistortImageOps.distortPL(distRight, rectRight, imageDistortRight); // convert for output final BufferedImage outLeft = ConvertBufferedImage.convertTo(rectLeft, null,true); final BufferedImage outRight = ConvertBufferedImage.convertTo(rectRight, null, true); // Add this rectified image SwingUtilities.invokeLater(new Runnable() { public void run() { gui.addItem(new RectifiedPairPanel(true, outLeft, outRight), name); }}); }
@Override public void process(T input) { super.initialize(input.width,input.height); if( isSaveOriginalReference() ) throw new IllegalArgumentException("The original reference cannot be saved"); if( tempImage == null ) { tempImage = (T)input.createNew(input.width,input.height); } for( int i = 0; i < scale.length; i++ ) { T prev = i == 0 ? input : getLayer(i-1); T layer = getLayer(i); // Apply the requested blur to the previous layer BlurStorageFilter<T> blur = (BlurStorageFilter<T>) FactoryBlurFilter.gaussian(layer.getImageType(), sigmaLayers[i],-1); tempImage.reshape(prev.width,prev.height); blur.process(prev,tempImage); // Resample the blurred image if( scale[i] == 1 ) { layer.setTo(tempImage); } else { PixelTransformAffine_F32 model = DistortSupport.transformScale(layer,tempImage, null); DistortImageOps.distortSingle(tempImage,layer, true, model,interpolate); } } }
/** * Finds an axis-aligned bounding box which would contain a image after it has been transformed. * The returned bounding box can be larger then the original image. * * @param srcWidth Width of the source image * @param srcHeight Height of the source image * @param transform Transform being applied to the image * @return Bounding box */ public static RectangleLength2D_F64 boundBox_F64( int srcWidth , int srcHeight , PixelTransform2_F64 transform ) { ImageRectangle_F64 r = new ImageRectangle_F64(); r.x0=r.y0=Double.MAX_VALUE; r.x1=r.y1=-Double.MAX_VALUE; for( int y = 0; y < srcHeight; y++ ) { transform.compute(0, y); updateBoundBox(transform, r); transform.compute(srcWidth, y); updateBoundBox(transform, r); } for( int x = 0; x < srcWidth; x++ ) { transform.compute(x, 0); updateBoundBox(transform, r); transform.compute(x, srcHeight); updateBoundBox(transform, r); } return new RectangleLength2D_F64(r.x0,r.y0,r.x1-r.x0,r.y1-r.y0); }
distortSingle((ImageGray) input, (ImageGray) output, model, interpType, borderType); } else if( input instanceof Planar) { distortPL((Planar) input, (Planar) output, model,borderType, interpType);
/** * <p> * Adjust the rectification such that the entire original left image can be seen. For use with * uncalibrated stereo images with unknown baseline. * </p> * * <p> * Input rectification matrices are overwritten with adjusted values on output. * </p> * * @param imageWidth Width of left image. * @param imageHeight Height of left image. * @param rectifyLeft Rectification matrix for left image. Input and Output. Modified. * @param rectifyRight Rectification matrix for right image. Input and Output. Modified. */ // TODO Delete this function? It should reasonably fill the old view in most non-pathological cases public static void fullViewLeft(int imageWidth,int imageHeight, DenseMatrix64F rectifyLeft, DenseMatrix64F rectifyRight ) { Point2Transform2_F32 tranLeft = new PointTransformHomography_F32(rectifyLeft); RectangleLength2D_F32 bound = DistortImageOps.boundBox_F32(imageWidth, imageHeight, new PointToPixelTransform_F32(tranLeft)); double scaleX = imageWidth/bound.width; double scaleY = imageHeight/bound.height; double scale = Math.min(scaleX,scaleY); adjustUncalibrated(rectifyLeft, rectifyRight, bound, scale); }
public static void fullViewLeft(CameraPinholeRadial paramLeft, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight, DMatrixRMaj rectifyK) { // need to take in account the order in which image distort will remove rectification later on paramLeft = new CameraPinholeRadial(paramLeft); Point2Transform2_F64 tranLeft = transformPixelToRect(paramLeft, rectifyLeft); RectangleLength2D_F64 bound = DistortImageOps.boundBox_F64(paramLeft.width, paramLeft.height, new PointToPixelTransform_F64(tranLeft)); double scaleX = paramLeft.width/bound.width; double scaleY = paramLeft.height/bound.height; double scale = Math.min(scaleX, scaleY); adjustCalibrated(rectifyLeft, rectifyRight, rectifyK, bound, scale); }
distortSingle((ImageGray)input, (ImageGray)output, model, interpType, borderType); } else if( input instanceof Planar) { distortPL((Planar) input, (Planar) output, model, borderType, interpType);
public static void fullViewLeft(CameraPinholeRadial paramLeft, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight, FMatrixRMaj rectifyK) { // need to take in account the order in which image distort will remove rectification later on paramLeft = new CameraPinholeRadial(paramLeft); Point2Transform2_F32 tranLeft = transformPixelToRect(paramLeft, rectifyLeft); RectangleLength2D_F32 bound = DistortImageOps.boundBox_F32(paramLeft.width, paramLeft.height, new PointToPixelTransform_F32(tranLeft)); float scaleX = paramLeft.width/bound.width; float scaleY = paramLeft.height/bound.height; float scale = (float)Math.min(scaleX, scaleY); adjustCalibrated(rectifyLeft, rectifyRight, rectifyK, bound, scale); }
bound = DistortImageOps.boundBox_F64(param.width, param.height, new PointToPixelTransform_F64(remove_p_to_p)); } else if( type == AdjustmentType.EXPAND) {
RectangleLength2D_F32 bound = DistortImageOps.boundBox_F32(paramLeft.width, paramLeft.height, new PointToPixelTransform_F32(tranLeft));
bound = DistortImageOps.boundBox_F64(paramOriginal.width, paramOriginal.height, new PointToPixelTransform_F64(ori_to_des)); } else if( type == AdjustmentType.EXPAND) { bound = LensDistortionOps_F64.boundBoxInside(paramOriginal.width, paramOriginal.height, new PointToPixelTransform_F64(ori_to_des));
bound = DistortImageOps.boundBox_F32(param.width, param.height, new PointToPixelTransform_F32(remove_p_to_p)); } else if( type == AdjustmentType.EXPAND) {
bound = DistortImageOps.boundBox_F32(paramOriginal.width, paramOriginal.height, new PointToPixelTransform_F32(ori_to_des)); } else if( type == AdjustmentType.EXPAND) { bound = LensDistortionOps_F32.boundBoxInside(paramOriginal.width, paramOriginal.height, new PointToPixelTransform_F32(ori_to_des));