@Override public void setF(int index, float[] value) { for( int i = 0; i < image.getNumBands(); i++ ) { image.data[index++] = value[i]; } }
@Override public void getF(int index, float[] value) { for( int i = 0; i < image.getNumBands(); i++ ) { value[i] = image.data[index++]; } }
public static void interleavedToBuffered( InterleavedF32 src, BufferedImage dst) { if (src.getNumBands() != 3) throw new IllegalArgumentException("src must have three bands"); final int width = dst.getWidth(); final int height = dst.getHeight(); for (int y = 0; y < height; y++) { int indexSrc = src.startIndex + src.stride * y; for (int x = 0; x < width; x++ ) { int c1 = (int)src.data[indexSrc++]; int c2 = (int)src.data[indexSrc++]; int c3 = (int)src.data[indexSrc++]; int argb = c1 << 16 | c2 << 8 | c3; dst.setRGB(x, y, argb); } } }
@Override public void setImage(InterleavedF32 image) { if( image.getNumBands() != temp0.length ) throw new IllegalArgumentException("Number of bands doesn't match"); super.setImage(image); } @Override
public ImplBilinearPixel_IL_F32(InterleavedF32 orig) { this(orig.getNumBands()); setImage(orig); }
public static void bufferedToInterleaved(BufferedImage src, InterleavedF32 dst) { final int width = src.getWidth(); final int height = src.getHeight(); if (dst.getNumBands() == 3) { for (int y = 0; y < height; y++) { int indexDst = dst.startIndex + y * dst.stride; for (int x = 0; x < width; x++) { int argb = src.getRGB(x, y); dst.data[indexDst++] = (argb >>> 16) & 0xFF; dst.data[indexDst++] = (argb >>> 8) & 0xFF; dst.data[indexDst++] = argb & 0xFF; } } } else if (dst.getNumBands() == 4) { for (int y = 0; y < height; y++) { int indexDst = dst.startIndex + y * dst.stride; for (int x = 0; x < width; x++) { int argb = src.getRGB(x, y); dst.data[indexDst++] = (argb >>> 24) & 0xFF; dst.data[indexDst++] = (argb >>> 16) & 0xFF; dst.data[indexDst++] = (argb >>> 8) & 0xFF; dst.data[indexDst++] = argb & 0xFF; } } } else if( dst.getNumBands() == 1 ){ ConvertRaster.bufferedToGray(src, dst); } else { throw new IllegalArgumentException("Unsupported number of input bands"); } }
/** * 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; } }
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] ); } } }
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 convert( InterleavedF32 from, InterleavedF64 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++] = ( double )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( double )( from.data[i] ); } } }
public static void convert( InterleavedF32 from, InterleavedI8 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++] = ( byte )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( byte )( from.data[i] ); } } }
public static void convert( InterleavedF32 from, InterleavedS32 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++] = ( int )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( int )( from.data[i] ); } } }
public static void horizontal( 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 endJ = src.width - (kernelWidth - 1); for( int i = 0; i < src.height; i++ ) { int indexDst = dst.startIndex + i*dst.stride+offset*numBands; for (int j = 0; j < endJ; j++) { int indexSrcStart = src.startIndex + i*src.stride + j*numBands; for (int band = 0; band < numBands; band++) { int indexSrc = indexSrcStart + band; float total = 0; for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) { total += (dataSrc[indexSrc] ) * dataKer[k]; } dataDst[indexDst++] = total; } } } }
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; } } } }
public static void interleavedToBuffered(InterleavedF32 src, ByteInterleavedRaster dst) { if (src.getNumBands() != dst.getNumBands()) throw new IllegalArgumentException("Unequal number of bands src = " + src.getNumBands() + " dst = " + dst.getNumBands()); final byte[] dstData = dst.getDataStorage(); final int numBands = dst.getNumBands(); final int length = src.width*numBands; int dstStride = dst.getScanlineStride(); int dstOffset = getOffset(dst); for (int y = 0; y < src.height; y++) { int indexSrc = src.startIndex + src.stride * y; int indexDst = dstOffset + dstStride*y; int indexSrcEnd = indexSrc+length; while( indexSrc < indexSrcEnd ) { dstData[indexDst++] = (byte)src.data[indexSrc++]; } } }
public static void interleavedToBuffered(InterleavedF32 src, IntegerInterleavedRaster dst) { if (src.getNumBands() != dst.getNumBands()) throw new IllegalArgumentException("Unequal number of bands src = " + src.getNumBands() + " dst = " + dst.getNumBands());
@Override protected void updateBackground(int x0, int y0, int x1, int y1, T frame) { transform.setModel(worldToCurrent); interpolateInput.setImage(frame); float minusLearn = 1.0f - learnRate; final int numBands = background.getNumBands()/2; for (int y = y0; y < y1; y++) { int indexBG = background.startIndex + y*background.stride + x0*background.numBands; for (int x = x0; x < x1; x++, indexBG += numBands*2 ) { transform.compute(x,y,work); if( work.x >= 0 && work.x < frame.width && work.y >= 0 && work.y < frame.height) { interpolateInput.get(work.x,work.y,pixelInput); for (int band = 0; band < numBands; band++) { int indexBG_band = indexBG + band*2; float inputValue = pixelInput[band]; float meanBG = background.data[indexBG_band]; float varianceBG = background.data[indexBG_band + 1]; if( varianceBG < 0) { background.data[indexBG_band] = inputValue; background.data[indexBG_band+1] = initialVariance; } else { float diff = meanBG-inputValue; background.data[indexBG_band] = minusLearn*meanBG + learnRate*inputValue; background.data[indexBG_band+1] = minusLearn*varianceBG + learnRate*diff*diff; } } } } } }
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; } } }
@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++; } } } }
final int numBands = input.getNumBands();