/** * 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; }
/** * Reshapes this image so that it's shape matches the input image * @param image Image whose shape will be matched */ public void matchShape( ImageBase image ) { reshape(image.width,image.height); }
/** * If null the dst is declared, otherwise it checks to see if the 'dst' as the same shape as 'src'. * * The returned image will be 8-bit RGB */ private static BufferedImage checkInputs(ImageBase src, BufferedImage dst) { if (dst != null) { if (dst.getWidth() != src.getWidth() || dst.getHeight() != src.getHeight()) { throw new IllegalArgumentException("image dimension are different"); } } else { dst = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_RGB); } return dst; }
/** * Creates an identical image. Note that if this image is a sub-image portions of hte image which are not part * of the sub-image are not copied. * * @return Clone of this image. */ @SuppressWarnings({"unchecked", "CloneDoesntDeclareCloneNotSupportedException", "CloneDoesntCallSuperClone"}) @Override public T clone() { T ret = createSameShape(); ret.setTo((T)this); return ret; } }
@Override public int getNextHeight() { return image.getWidth(); }
@Override public void processImage(int sourceID, long frameID, BufferedImage buffered, final ImageBase undistorted) { // do this here instead of a reshape to ensure the number of bands is the same distorted = (T)undistorted.createSameShape(); BufferedImage tmp = distortedBuff; distortedBuff = ConvertBufferedImage.checkDeclare( undistorted.width,undistorted.height,distortedBuff,buffered.getType()); if( tmp != distortedBuff ) { distorted.reshape(undistorted.width, undistorted.height); this.undistorted.reshape(undistorted.width, undistorted.height); gui.setPreferredSize(new Dimension(undistorted.width,undistorted.height)); alg.setImageShape(undistorted.width,undistorted.height); synchronized (pointsUndistorted){ validTransform = false; pointsUndistorted.clear(); pointsDistorted.clear(); } } if( inputMethod == InputMethod.IMAGE ) { this.undistorted.setTo((T)undistorted); } renderDistorted(buffered, (T)undistorted); }
@Override public int getNextHeight() { return image.getHeight(); }
ImageType typeIn = input.getImageType(); ImageType typeOut = output.getImageType(); if( output instanceof ImageGray) { if (input.getClass() == output.getClass()) { output.setTo(input); } else { try { output.setTo(input); } else { try {
temp = (T)input.createNew(1,1); setFirstLayer(input); } else { getLayer(0).setTo(input); vertical.setSkip(skip); temp.reshape(input.width/skip,input.height); horizontal.process(input,temp); vertical.process(temp,getLayer(0)); int skip = scale[index]/scale[index-1]; T prev = getLayer(index-1); temp.reshape(prev.width/skip,prev.height);
@Override public void processImage(int sourceID, long frameID, final BufferedImage buffered, ImageBase input) { // strip away distortion parameters CameraPinhole desired = new CameraPinhole(param); // distorted image dist = (T)input.clone(); // storage for undistorted image undist = (T)input.createSameShape(); // show results and draw a horizontal line where the user clicks to see rectification easier SwingUtilities.invokeLater(() -> { gui.reset(); gui.addItem(new ImagePanel(buffered), "Original"); }); // add different types of adjustments Point2Transform2_F32 add_p_to_p = LensDistortionOps_F32.transformChangeModel(AdjustmentType.NONE, param,desired,true,null); addUndistorted("No Adjustment", add_p_to_p); Point2Transform2_F32 expand = LensDistortionOps_F32.transformChangeModel(AdjustmentType.EXPAND, param,desired, true, null); addUndistorted("Expand", expand); Point2Transform2_F32 fullView = LensDistortionOps_F32.transformChangeModel(AdjustmentType.FULL_VIEW,param, desired,true, null); addUndistorted("Full View", fullView); Point2Transform2_F32 center = LensDistortionOps_F32.transformChangeModel(AdjustmentType.CENTER,param, desired,true, null); addUndistorted("Center", center); }
private static boolean checkInBounds( ImageBase b , int c_x , int c_y , int dx , int dy , float c , float s ) { float x = c_x + c*dx - s*dy; float y = c_y + s*dx + c*dy; return b.isInBounds((int) x, (int) y); }
/** * Configuration constructor * @param distort Used to apply image distortion from different input images * @param equiWidth Width of output equirectangular image * @param equiHeight Height of output equirectangular image * @param imageType Type of image it processes and outputs. Must be floating point. Hmm why isn't this fixed? */ public MultiCameraToEquirectangular(ImageDistort<T,T> distort , int equiWidth , int equiHeight , ImageType<T> imageType ) { if( imageType.getDataType().isInteger() || imageType.getDataType().getNumBits() != 32 ) throw new IllegalArgumentException("Must be a 32 bit floating point image"); this.distort = distort; this.equiWidth = equiWidth; this.equHeight = equiHeight; tools.configure(equiWidth, equiHeight); weightImage = new GrayF32(equiWidth,equiHeight); averageImage = imageType.createImage(equiWidth, equiHeight); workImage = averageImage.createSameShape(); cameraRendered = averageImage.createSameShape(); }
@Override protected Object[] reformatForValidation(Method m, Object[] targetParam) { Object[] ret = new Object[ targetParam.length ]; for( int i = 0; i < targetParam.length; i++ ) { if( ImageBase.class.isAssignableFrom(targetParam[i].getClass()) ) { ret[i] = ((ImageBase)targetParam[i]).clone(); } else { ret[i] = targetParam[i]; } } return ret; }
@Override public int getNextWidth() { return image.getWidth(); }
public int getHeight() { if( sequence == null ) return queueBoof[selected].getHeight(); return sequence.getNextHeight(); }
/** * Specifies the initial target location so that it can learn its description * @param image Image * @param initial Initial target location and the mean-shift bandwidth */ public void initialize( T image , RectangleLength2D_I32 initial ) { if( !image.isInBounds(initial.x0,initial.y0) ) throw new IllegalArgumentException("Initial rectangle is out of bounds!"); if( !image.isInBounds(initial.x0+initial.width,initial.y0+initial.height) ) throw new IllegalArgumentException("Initial rectangle is out of bounds!"); pdf.reshape(image.width,image.height); ImageMiscOps.fill(pdf,-1); location.set(initial); // massage the rectangle so that it has an odd width and height // otherwise it could experience a bias when localizing location.width += 1-location.width%2; location.height += 1-location.height%2; failed = false; // compute the initial sum of the likelihood so that it can detect when the target is no longer visible minimumSum = 0; targetModel.setImage(image); for( int y = 0; y < initial.height; y++ ) { for( int x = 0; x < initial.width; x++ ) { minimumSum += targetModel.compute(x+initial.x0,y+initial.y0); } } minimumSum *= minFractionDrop; }
/** * Configuration constructor * @param distort Used to apply image distortion from different input images * @param equiWidth Width of output equirectangular image * @param equiHeight Height of output equirectangular image * @param imageType Type of image it processes and outputs. Must be floating point. Hmm why isn't this fixed? */ public MultiCameraToEquirectangular(ImageDistort<T,T> distort , int equiWidth , int equiHeight , ImageType<T> imageType ) { if( imageType.getDataType().isInteger() || imageType.getDataType().getNumBits() != 32 ) throw new IllegalArgumentException("Must be a 32 bit floating point image"); this.distort = distort; this.equiWidth = equiWidth; this.equHeight = equiHeight; tools.configure(equiWidth, equiHeight); weightImage = new GrayF32(equiWidth,equiHeight); averageImage = imageType.createImage(equiWidth, equiHeight); workImage = averageImage.createSameShape(); cameraRendered = averageImage.createSameShape(); }
@Override public ImageType<T> getImageType() { return output.getImageType(); }
/** * If null the dst is declared, otherwise it checks to see if the 'dst' as the same shape as 'src'. * * The returned image will be 8-bit RGB */ private static BufferedImage checkInputs(ImageBase src, BufferedImage dst) { if (dst != null) { if (dst.getWidth() != src.getWidth() || dst.getHeight() != src.getHeight()) { throw new IllegalArgumentException("image dimension are different. src=" +src.width+"x"+src.height+" dst="+dst.getWidth()+"x"+dst.getHeight()); } } else { dst = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_RGB); } return dst; }