/** * Converts a {@link ImageMultiBand} into a {@link ImageGray} by computing the average value of each pixel * across all the bands. * * @param input ImageMultiBand that is being converted. Not modified. * @param output (Optional) The single band output image. If null a new image is created. Modified. * @return Converted image. */ public static <T extends ImageGray<T>>T average( ImageMultiBand input , T output ) { if( input instanceof Planar ) { return (T)average((Planar)input,output); } else if( input instanceof ImageInterleaved ) { return (T)average((ImageInterleaved)input,output); } else { throw new RuntimeException("Unknown multiband image"); } }
@Override public void process(I src, O dst) { GConvertImage.convert(src,dst); }
Planar ms = (Planar)output; for (int i = 0; i < ms.getNumBands(); i++) { convert(input,ms.getBand(i)); int h = output.height; ImageGray tmp = GeneralizedImageOps.createSingleBand(mi.getImageType().getDataType(),w,h); average(mi,tmp); convert(tmp,so); } else { average(mi,so); } else { for (int i = 0; i < mi.getNumBands(); i++) { convert(mi.getBand(i), mo.getBand(i)); int h = output.height; ImageGray tmp = GeneralizedImageOps.createSingleBand(mb.getImageType().getDataType(),w,h); average(mb,tmp); convert(tmp,so); } else { average(mb,so);
@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); }
public void process(final BufferedImage buffLeft, final BufferedImage buffRight) { imageLeft.reshape(buffLeft.getWidth(), buffLeft.getHeight()); imageRight.reshape(buffRight.getWidth(), buffRight.getHeight()); grayLeft.reshape(buffLeft.getWidth(), buffLeft.getHeight()); grayRight.reshape(buffRight.getWidth(), buffRight.getHeight()); ConvertBufferedImage.convertFromPlanar(buffLeft, imageLeft, true, imageType); ConvertBufferedImage.convertFromPlanar(buffRight, imageRight, true, imageType); GConvertImage.average(imageLeft, grayLeft); GConvertImage.average(imageRight, grayRight); SwingUtilities.invokeLater(new Runnable() { public void run() { panel.setImages(buffLeft, buffRight); processedImage = true; doRefreshAll(); } }); }
@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); }
GConvertImage.average((Planar<I>)frame, gray); grayScale = true;
@Override public void process(T input) { workspace.reshape(input.width,input.height); GConvertImage.convert(input,workspace); describer.process(workspace); }
@Override public void setImage(Planar<T> image) { gray.reshape(image.width,image.height); grayII.reshape(image.width,image.height); bandII.reshape(image.width,image.height); GConvertImage.average(image, gray); GIntegralImageOps.transform(gray, grayII); for( int i = 0; i < image.getNumBands(); i++) GIntegralImageOps.transform(image.getBand(i), bandII.getBand(i)); alg.setImage(grayII,bandII); }
@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; } }
@Override public void detect(Planar<T> input) { gray.reshape(input.width,input.height); grayII.reshape(input.width,input.height); bandII.reshape(input.width,input.height); GConvertImage.average(input,gray); GIntegralImageOps.transform(gray, grayII); for( int i = 0; i < input.getNumBands(); i++) GIntegralImageOps.transform(input.getBand(i), bandII.getBand(i)); alg.detect(grayII,bandII); }
/** * 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++; } } } }