@Override public void setF(int index, float[] value) { for( int i = 0; i < image.getNumBands(); i++ ) { image.data[index++] = value[i]; } }
/** * <p> * Converts an {@link boofcv.struct.image.InterleavedU8} into a {@link boofcv.struct.image.InterleavedF32}. * </p> * * @param input Input image which is being converted. Not modified. * @param output (Optional) The output image. If null a new image is created. Modified. * @return Converted image. */ public static InterleavedF32 convert(InterleavedU8 input, InterleavedF32 output) { if (output == null) { output = new InterleavedF32(input.width, input.height, input.numBands); } else { output.reshape(input.width,input.height,input.numBands); } ImplConvertImage.convert(input, output); return output; }
@Override public ImageType<InterleavedF32> getImageType() { return orig.getImageType(); }
public static void convolve( Kernel2D_F32 kernel , InterleavedF32 src , InterleavedF32 dst ) { final float[] dataKernel = kernel.data; final float[] dataSrc = src.data; final float[] dataDst = dst.data; final int width = src.getWidth(); final int height = src.getHeight(); final int numBands = src.getNumBands(); int offsetL = kernel.offset; int offsetR = kernel.width-kernel.offset-1; for( int y = offsetL; y < height-offsetR; y++ ) { int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands; for( int x = offsetL; x < width-offsetR; x++ ) { int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands; for (int band = 0; band < numBands; band++) { float total = 0; int indexKer = 0; for( int ki = 0; ki < kernel.width; ki++ ) { int indexSrc = indexSrcStart+ki*src.stride + band; for( int kj = 0; kj < kernel.width; kj++ ) { total += (dataSrc[indexSrc] )* dataKernel[indexKer++]; indexSrc += numBands; } } dataDst[indexDst++] = total; } } } }
float ra = transform.getBand(x,y,0); float ia = transform.getBand(x,y,1); float rb = transform.getBand(x+hw,y+hh,0); float ib = transform.getBand(x+hw,y+hh,1); transform.setBand(x,y,0,rb); transform.setBand(x,y,1,ib); transform.setBand(x+hw,y+hh,0,ra); transform.setBand(x+hw,y+hh,1,ia); ra = transform.getBand(x+hw,y,0); ia = transform.getBand(x+hw,y,1); rb = transform.getBand(x,y+hh,0); ib = transform.getBand(x,y+hh,1); transform.setBand(x+hw,y,0,rb); transform.setBand(x+hw,y,1,ib); transform.setBand(x,y+hh,0,ra); transform.setBand(x,y+hh,1,ia); InterleavedF32 storageTL = new InterleavedF32(hw1,hh1,2); storageTL.setTo(transform.subimage(0, 0, hw1, hh1, null)); InterleavedF32 storageTR = new InterleavedF32(hw,hh1,2); storageTR.setTo(transform.subimage(hw1, 0, w, hh1, null)); transform.subimage(0,0,hw,hh, null).setTo(transform.subimage(hw1,hh1,w,h, null));
public static void convert( InterleavedF32 from, InterleavedI16 to ) { if (from.isSubimage() || to.isSubimage()) { final int N = from.width * from.getNumBands(); for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < N; x++) { to.data[indexTo++] = ( short )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( short )( from.data[i] ); } } }
final int width = input.getWidth(); final int height = input.getHeight(); final int numBands = input.getNumBands(); input.get(j,y, pixel); for (int band = 0; band < numBands; band++) { total[band] += pixel[band]*v; total[band] /= weight; output.set(x,y, total );
/** * Converts an NV21 image into a {@link InterleavedF32} RGB image. * * @param data Input: NV21 image data * @param width Input: NV21 image width * @param height Input: NV21 image height * @param output Output: Optional storage for output image. Can be null. */ public static InterleavedF32 nv21ToInterleaved( byte[] data , int width , int height , InterleavedF32 output ) { if( output == null ) { output = new InterleavedF32(width,height,3); } else if( output.width != width || output.height != height ) throw new IllegalArgumentException("output width and height must be "+width+" "+height); else if( output.getNumBands() != 3 ) throw new IllegalArgumentException("three bands expected"); ImplConvertNV21.nv21ToInterleaved_F32(data, 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 InterleavedF32 createNew(int imgWidth, int imgHeight) { if (imgWidth == -1 || imgHeight == -1) return new InterleavedF32(); return new InterleavedF32(imgWidth, imgHeight, numBands); }
public static void average( InterleavedF32 from , GrayF32 to ) { final int numBands = from.getNumBands(); int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); System.arraycopy(from.data,indexFrom,to.data,indexTo,from.width); int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); int indexEndTo = indexTo + from.width; int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); int indexEndTo = indexTo + from.width; int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y);
/** * 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 inverse(InterleavedF32 transform, GrayF32 image ) { DiscreteFourierTransformOps.checkImageArguments(image,transform); if( image.isSubimage() || transform.isSubimage() ) throw new IllegalArgumentException("Subimages are not supported"); checkDeclareAlg(image); // If he user lets us, modify the transform InterleavedF32 workImage; if(modifyInputs) { workImage = transform; } else { tmp.reshape(transform.width,transform.height); tmp.setTo(transform); workImage = tmp; } alg.complexInverse(workImage.data, true); // copy the real portion. imaginary should be zeros int N = image.width*image.height; for( int i = 0; i < N; i++ ) { image.data[i] = workImage.data[i*2]; } }
@Override public void reset() { background.reshape(1,1); }
public static void vertical( Kernel1D_F32 kernel, InterleavedF32 src, InterleavedF32 dst ) { final float[] dataSrc = src.data; final float[] dataDst = dst.data; final float[] dataKer = kernel.data; final int offset = kernel.getOffset(); final int kernelWidth = kernel.getWidth(); final int numBands = src.getNumBands(); final int imgWidth = dst.getWidth(); final int imgHeight = dst.getHeight(); final int yEnd = imgHeight-(kernelWidth-offset-1); for( int y = offset; y < yEnd; y++ ) { int indexDst = dst.startIndex+y*dst.stride; int indexSrcStart = src.startIndex+(y-offset)*src.stride; for (int x = 0; x < imgWidth; x++) { for (int band = 0; band < numBands; band++) { int indexSrc = indexSrcStart + band; float total = 0; for (int k = 0; k < kernelWidth; k++) { total += (dataSrc[indexSrc] )* dataKer[k]; indexSrc += src.stride; } dataDst[indexDst++] = total; } indexSrcStart += numBands; } } }
public static void convert( InterleavedF32 from, InterleavedS64 to ) { if (from.isSubimage() || to.isSubimage()) { final int N = from.width * from.getNumBands(); for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < N; x++) { to.data[indexTo++] = ( long )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( long )( from.data[i] ); } } }
public static void vertical(Kernel1D_F32 kernel, InterleavedF32 input, InterleavedF32 output ) { final int offset = kernel.getOffset(); final int width = input.getWidth(); final int height = input.getHeight(); final int numBands = input.getNumBands(); final float[] pixel = new float[ numBands ]; final float[] total = new float[ numBands ]; for (int y = 0; y < height; y++) { for( int x = 0; x < width; x++ ) { Arrays.fill(total,0); float weight = 0; int startY = y - offset; int endY = startY + kernel.getWidth(); if( startY < 0 ) startY = 0; if( endY > height ) endY = height; for( int i = startY; i < endY; i++ ) { float v = kernel.get(i-y+offset); input.get(x,i, pixel); for (int band = 0; band < numBands; band++) { total[band] += pixel[band]*v; } weight += v; } for (int band = 0; band < numBands; band++) { total[band] /= weight; } output.set(x,y, total); } } }
background.reshape(frame.width, frame.height); int numBands = background.getNumBands()/2; float minusLearn = 1.0f - learnRate;
public ThresholdBlockMinMax_F32(float minimumSpread, ConfigLength requestedBlockWidth, float scale , boolean down , boolean thresholdFromLocalBlocks) { super(minimumSpread,requestedBlockWidth,thresholdFromLocalBlocks,GrayF32.class); stats = new InterleavedF32(1,1,2); this.scale = scale; this.down = down; }