@Override public void process(I src, O dst) { GConvertImage.convert(src,dst); }
@Override public void setImage(T image) { GrayF32 input; if( image instanceof GrayF32) { input = (GrayF32)image; } else { imageFloat.reshape(image.width,image.height); GConvertImage.convert(image,imageFloat); input = imageFloat; } scaleSpace.setImage(input); }
@Override public void detect(T image) { GrayF32 input; if( image instanceof GrayF32) { input = (GrayF32)image; } else { imageFloat.reshape(image.width,image.height); GConvertImage.convert(image,imageFloat); input = imageFloat; } detector.process(input); }
@Override public void process(T input) { workspace.reshape(input.width,input.height); GConvertImage.convert(input,workspace); describer.process(workspace); }
@Override public void detect(T input) { if( input instanceof GrayF32) { converted = (GrayF32)input; } else { converted.reshape(input.width,input.height); GConvertImage.convert(input, converted); } if( !detector.process(converted) ) { targetDetected = false; return; } else { targetDetected = true; } }
/** * Converts an image from one type to another type. Creates a new image instance if * an output is not provided. * * @param src Input image. Not modified. * @param dst Converted output image. If null a new one will be declared. Modified. * @param typeDst The type of output image. * @return Converted image. */ public static <T extends ImageGray<T>> T convert(ImageGray<?> src , T dst , Class<T> typeDst ) { if (dst == null) { dst =(T) createSingleBand(typeDst, src.width, src.height); } else { InputSanityCheck.checkSameShape(src, dst); } GConvertImage.convert(src,dst); return dst; }
@Override public void detect(In input) { if( input instanceof GrayF32) alg.process((GrayF32)input); else { imageFloat.reshape(input.width,input.height); GConvertImage.convert(input,imageFloat); alg.process(imageFloat); } }
@Override public void process(T input, GrayU8 output) { if( this.work == null ) alg.process(input,output); else { this.work.reshape(input.width,input.height); GConvertImage.convert(input,this.work); alg.process(this.work,output); } }
@Override public void setImage(T image) { GrayF32 input; if( image instanceof GrayF32) { input = (GrayF32)image; } else { imageFloat.reshape(image.width,image.height); GConvertImage.convert(image,imageFloat); input = imageFloat; } scaleSpace.setImage(input); setObjectRadius(sigma*BoofDefaults.SIFT_SCALE_TO_RADIUS); }
@Override public void updateBackground( T frame) { if( background.width == 1 ) { background.reshape(frame.width, frame.height); GConvertImage.convert(frame, background); return; } else { InputSanityCheck.checkSameShape(background,frame); } inputWrapper.wrap(frame); float minusLearn = 1.0f - learnRate; int indexBG = 0; for (int y = 0; y < frame.height; y++) { int indexInput = frame.startIndex + y*frame.stride; int end = indexInput + frame.width; while( indexInput < end ) { float value = inputWrapper.getF(indexInput++); float bg = background.data[indexBG]; background.data[indexBG++] = minusLearn*bg + learnRate*value; } } }
/** * Applies {@link boofcv.alg.filter.binary.impl.ThresholdSauvola Sauvola} thresholding to the input image. * Intended for use with text image. * * @see boofcv.alg.filter.binary.impl.ThresholdSauvola * * @param input Input image. * @param output (optional) Output binary image. If null it will be declared internally. * @param width Width of square region. * @param k Positive parameter used to tune threshold. Try 0.3 * @param down Should it threshold up or down. * @return binary image */ public static <T extends ImageGray<T>> GrayU8 localSauvola(T input, GrayU8 output, ConfigLength width, float k, boolean down) { ThresholdSauvola alg = new ThresholdSauvola(width,k, down); if( output == null ) output = new GrayU8(input.width,input.height); if( input instanceof GrayF32) { alg.process((GrayF32)input,output); } else { GrayF32 conv = new GrayF32(input.width,input.height); GConvertImage.convert(input, conv); alg.process(conv,output); } return output; }
/** * Applies {@link boofcv.alg.filter.binary.ThresholdNick NICK} thresholding to the input image. * Intended for use with text image. * * @see boofcv.alg.filter.binary.ThresholdNick * * @param input Input image. * @param output (optional) Output binary image. If null it will be declared internally. * @param width Width of square region. * @param k Positive parameter used to tune threshold. Try -0.1 to -0.2 * @param down Should it threshold up or down. * @return binary image */ public static <T extends ImageGray<T>> GrayU8 localNick(T input, GrayU8 output, ConfigLength width, float k, boolean down) { ThresholdNick alg = new ThresholdNick(width,k, down); if( output == null ) output = new GrayU8(input.width,input.height); if( input instanceof GrayF32) { alg.process((GrayF32)input,output); } else { GrayF32 conv = new GrayF32(input.width,input.height); GConvertImage.convert(input, conv); alg.process(conv,output); } return output; }
@Override public void updateBackground( T frame) { if( background.width == 1 ) { background.reshape(frame.width, frame.height); GConvertImage.convert(frame, background); return; } else { InputSanityCheck.checkSameShape(background,frame); } inputWrapper.wrap(frame); int numBands = background.getNumBands(); float minusLearn = 1.0f - learnRate; int indexBG = 0; for (int y = 0; y < frame.height; y++) { int indexInput = frame.startIndex + y*frame.stride; int end = indexInput + frame.width*numBands; while( indexInput < end ) { int endIndexBG = indexBG + numBands; while( indexBG < endIndexBG ) { float valueBG = background.data[indexBG]; background.data[indexBG] = minusLearn*valueBG + learnRate*inputWrapper.getF(indexInput); indexBG++; indexInput++; } } } }
@Override public void invert(GrayS32 transformed, T original) { copyInput.reshape(transformed.width,transformed.height); temp.reshape(transformed.width,transformed.height); copyInput.setTo(transformed); if( original.getDataType().getDataType() == int.class ) { WaveletTransformOps. inverseN(desc, copyInput, (GrayS32) original, temp, numLevels, minPixelValue, maxPixelValue); } else { copyOutput.reshape(original.width,original.height); WaveletTransformOps.inverseN(desc, copyInput, copyOutput,temp,numLevels,minPixelValue,maxPixelValue); GConvertImage.convert(copyOutput,original); } }
@Override public void updateBackground( Planar<T> frame) { if( background.width == 1 ) { background.reshape(frame.width, frame.height); GConvertImage.convert(frame, background); return; } else { InputSanityCheck.checkSameShape(background,frame); } inputWrapper.wrap(frame); int numBands = background.getNumBands(); float minusLearn = 1.0f - learnRate; int indexBG = 0; for (int y = 0; y < frame.height; y++) { int indexInput = frame.startIndex + y*frame.stride; int end = indexInput + frame.width; while( indexInput < end ) { inputWrapper.getF(indexInput, inputPixels); for (int band = 0; band < numBands; band++) { GrayF32 backgroundBand = background.getBand(band); backgroundBand.data[indexBG] = minusLearn*backgroundBand.data[indexBG] + learnRate*inputPixels[band]; } indexInput++; indexBG++; } } }
@Override public GrayS32 transform(T original, GrayS32 transformed) { if( transformed == null ) { ImageDimension d = UtilWavelet.transformDimension(original,numLevels); transformed = new GrayS32(d.width,d.height); } temp.reshape(transformed.width,transformed.height); copyInput.reshape(original.width,original.height); if( original.getDataType().getDataType() == int.class ) { copyInput.setTo((GrayS32)original); } else { GConvertImage.convert(original, copyInput); } WaveletTransformOps.transformN(desc, copyInput,transformed,temp,numLevels); return transformed; }
if( output == null ) output = new GrayU8(input.width,input.height); convert(input,output); return output;
@Override public void updateBackground( T frame) { if( background.width == 1 ) { background.reshape(frame.width, frame.height); GConvertImage.convert(frame, background.getBand(0)); GImageMiscOps.fill(background.getBand(1),initialVariance); return; } else { InputSanityCheck.checkSameShape(background, frame); } inputWrapper.wrap(frame); float minusLearn = 1.0f - learnRate; GrayF32 backgroundMean = background.getBand(0); GrayF32 backgroundVar = background.getBand(1); int indexBG = 0; for (int y = 0; y < background.height; y++) { int indexInput = frame.startIndex + y*frame.stride; int end = indexInput + frame.width; while( indexInput < end ) { float inputValue = inputWrapper.getF(indexInput); float meanBG = backgroundMean.data[indexBG]; float varianceBG = backgroundVar.data[indexBG]; float diff = meanBG-inputValue; backgroundMean.data[indexBG] = minusLearn*meanBG + learnRate*inputValue; backgroundVar.data[indexBG] = minusLearn*varianceBG + learnRate*diff*diff; indexBG++; indexInput++; } } }
@Override public void segment(T input, GrayS32 output) { InputSanityCheck.checkSameShape(input,output); converted.reshape(input.width,input.height); GConvertImage.convert(input,converted); // segment the image alg.process(converted); alg.removeWatersheds(); numRegions = alg.getTotalRegions(); GrayS32 pixelToRegion = alg.getOutput(); // Merge small regions together if( pruneSmall != null ) { regionMemberCount.resize(numRegions); regionColor.resize(numRegions); ImageSegmentationOps.countRegionPixels(pixelToRegion,numRegions,regionMemberCount.data); pruneSmall.process(converted,pixelToRegion,regionMemberCount,regionColor); numRegions = regionMemberCount.size(); } output.setTo(pixelToRegion); }