@Override public void updateBackground( T frame) { inputWrapper.wrap(frame); inputWrapper.get(x,y,inputPixel); for (int i = 0; i < frame.numBands; i++) { bgPixel[i*2] = inputPixel[i]; bgPixel[i*2+1] = initialVariance; bgWrapper.set(x,y,bgPixel); int end = indexInput + frame.width*numBands; while( indexInput < end ) { inputWrapper.getF(indexInput, inputPixel);
GImageMultiBand b = FactoryGImageMultiBand.wrap(imgB); float valueA[] = new float[ a.getNumberOfBands() ]; float valueB[] = new float[ b.getNumberOfBands() ]; a.get(x,y, valueA); b.get(x,y, valueB); for (int i = 0; i < a.getNumberOfBands(); i++) { double valA = valueA[i]; double valB = valueB[i];
@Override protected void updateBackground(int x0, int y0, int x1, int y1, Planar<T> frame) { transform.setModel(worldToCurrent); interpolationInput.setImage(frame); final int numBands = frame.getNumBands(); float minusLearn = 1.0f - learnRate; for (int y = y0; y < y1; y++) { int indexBG = background.startIndex + y*background.stride + x0; for (int x = x0; x < x1; x++, indexBG++ ) { transform.compute(x,y,work); if( work.x >= 0 && work.x < frame.width && work.y >= 0 && work.y < frame.height) { interpolationInput.get(work.x,work.y, pixelInput); backgroundWrapper.getF(indexBG,pixelBack); for (int band = 0; band < numBands; band++) { float value = pixelInput[band]; float bg = pixelBack[band]; if( bg == Float.MAX_VALUE ) { pixelBack[band] = value; } else { pixelBack[band] = minusLearn*bg + learnRate*value; } } backgroundWrapper.setF(indexBG,pixelBack); } } } }
/** * Configurations background removal. * * @param learnRate Specifies how quickly the background is updated. 0 = static 1.0 = instant. Try 0.05 * @param threshold Threshold for background. Consult a chi-square table for reasonably values. * 10 to 16 for 1 to 3 bands. * @param imageType Type of input image. */ public BackgroundStationaryGaussian_PL(float learnRate, float threshold, ImageType<Planar<T>> imageType) { super(learnRate, threshold, imageType); int numBands = imageType.getNumBands(); background = new Planar<>(GrayF32.class,1,1,2*numBands); bgWrapper = FactoryGImageMultiBand.create(background.getImageType()); bgWrapper.wrap(background); inputWrapper = FactoryGImageMultiBand.create(imageType); inputPixel = new float[numBands]; }
/** * Configurations background removal. * * @param learnRate Specifies how quickly the background is updated. 0 = static 1.0 = instant. Try 0.05 * @param threshold Threshold for background. Consult a chi-square table for reasonably values. * 10 to 16 for 1 to 3 bands. * @param imageType Type of input image. */ public BackgroundStationaryGaussian_IL(float learnRate, float threshold, ImageType<T> imageType) { super(learnRate, threshold, imageType); int numBands = imageType.getNumBands(); background = new InterleavedF32(1,1,2*numBands); bgWrapper = FactoryGImageMultiBand.create(background.getImageType()); bgWrapper.wrap(background); inputWrapper = FactoryGImageMultiBand.create(imageType); inputPixel = new float[numBands]; bgPixel = new float[numBands*2]; }
@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++; } } } }
public BackgroundMovingBasic_PL(float learnRate, float threshold, Point2Transform2Model_F32<Motion> transform, InterpolationType interpType, ImageType<Planar<T>> imageType) { super(learnRate, threshold,transform, imageType); this.interpolationInput = FactoryInterpolation.createPixelMB(0, 255, interpType,BorderType.EXTENDED,imageType); int numBands = imageType.getNumBands(); background = new Planar<>(GrayF32.class,1,1,numBands); this.interpolationBG = FactoryInterpolation.createPixelMB( 0, 255, interpType, BorderType.EXTENDED, ImageType.pl(numBands, GrayF32.class)); this.interpolationBG.setImage(background); pixelInput = new float[numBands]; pixelBack = new float[numBands]; backgroundWrapper = FactoryGImageMultiBand.create(ImageType.pl(numBands, GrayF32.class)); backgroundWrapper.wrap(background); inputWrapper = FactoryGImageMultiBand.create(imageType); }
@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++; } } }