/** * Sets the pixel's value for all the bands using an array. * * @param x pixel coordinate. * @param y pixel coordinate. * @param value The pixel's new value for each band. */ public void set(int x, int y, short... value) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds"); int index = getIndex(x, y, 0); for (int i = 0; i < numBands; i++, index++) { data[index] = value[i]; } }
/** * Fills one band in the image with the specified value * * @param input An image. * @param band Which band is to be filled with the specified value * @param value The value that the image is being filled with. */ public static void fillBand(InterleavedI16 input, int band , int value) { final int numBands = input.numBands; for (int y = 0; y < input.height; y++) { int index = input.getStartIndex() + y * input.getStride() + band; int end = index + input.width*numBands - band; for (; index < end; index += numBands ) { input.data[index] = (short)value; } } }
final int offsetR = kernelWidth-offsetL-1; final int imgWidth = output.getWidth(); final int imgHeight = output.getHeight(); final int numBands = output.getNumBands(); final int total[] = new int[ numBands ];
public static void convert( InterleavedU16 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++] & 0xFFFF); } } } else { final int N = from.width * from.height * from.getNumBands(); System.arraycopy(from.data, 0, to.data, 0, N); } }
public static void vertical( Kernel1D_S32 kernel, InterleavedS16 src, InterleavedI16 dst ) { final short[] dataSrc = src.data; final short[] dataDst = dst.data; final int[] 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; int total = 0; for (int k = 0; k < kernelWidth; k++) { total += (dataSrc[indexSrc] )* dataKer[k]; indexSrc += src.stride; } dataDst[indexDst++] = (short)total; } indexSrcStart += numBands; } } }
total[band] = (total[band]+weight/2)/weight; output.set(x,y, total );
@Override public void unsafe_set(int x, int y, int... value) { int index = getIndex(x, y, 0); for (int i = 0; i < numBands; i++, index++) { data[index] = (short)value[i]; } }
final int numBands = dst.getNumBands(); final int total[] = new int[ numBands ];
public static void horizontal(Kernel1D_S32 kernel, ImageBorder_IL_S32 src, InterleavedI16 dst ) { final int offset = kernel.getOffset(); final int kernelWidth = kernel.getWidth(); final int width = dst.getWidth(); final int height = dst.getHeight(); final int borderRight = kernelWidth-offset-1; final int numBands = dst.getNumBands();
public static void convert( InterleavedS16 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++] = ( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height * from.getNumBands(); System.arraycopy(from.data, 0, to.data, 0, N); } }
public static void vertical( Kernel1D_S32 kernel, InterleavedU8 src, InterleavedI16 dst ) { final byte[] dataSrc = src.data; final short[] dataDst = dst.data; final int[] 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; int total = 0; for (int k = 0; k < kernelWidth; k++) { total += (dataSrc[indexSrc] & 0xFF)* dataKer[k]; indexSrc += src.stride; } dataDst[indexDst++] = (short)total; } indexSrcStart += numBands; } } }
public static void vertical(Kernel1D_S32 kernel, InterleavedS16 input, InterleavedI16 output ) { final int offset = kernel.getOffset(); final int width = input.getWidth(); final int height = input.getHeight(); final int numBands = input.getNumBands(); final int[] pixel = new int[ numBands ]; final int[] total = new int[ numBands ]; for (int y = 0; y < height; y++) { for( int x = 0; x < width; x++ ) { Arrays.fill(total,0); int 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++ ) { int 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] = (total[band]+weight/2)/weight; } output.set(x,y, total); } } }
/** * Rotates the image 90 degrees in the clockwise direction. */ public static void rotateCW( InterleavedI16 input , InterleavedI16 output ) { if( input.width != output.height || input.height != output.width || input.numBands != output.numBands ) throw new IllegalArgumentException("Incompatible shapes"); int h = input.height-1; for( int y = 0; y < input.height; y++ ) { int indexSrc = input.startIndex + y*input.stride; for (int x = 0; x < input.width; x++) { int indexDst = output.getIndex(h-y,x); int end = indexSrc + input.numBands; while( indexSrc != end ) { output.data[indexDst++] = input.data[indexSrc++]; } } } }
public static void vertical(Kernel1D_S32 kernel, ImageBorder_IL_S32 src, InterleavedI16 dst ) { final int offset = kernel.getOffset(); final int kernelWidth = kernel.getWidth(); final int width = dst.getWidth(); final int height = dst.getHeight(); final int borderBottom = kernelWidth-offset-1; final int numBands = dst.getNumBands();
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] ); } } }
/** * Fills each band in the image with the specified values * * @param input An image. * @param values Array which contains the values each band is to be filled with. */ public static void fill(InterleavedI16 input, int[] values) { final int numBands = input.numBands; for (int y = 0; y < input.height; y++) { for( int band = 0; band < numBands; band++ ) { int index = input.getStartIndex() + y * input.getStride() + band; int end = index + input.width*numBands - band; int value = values[band]; for (; index < end; index += numBands ) { input.data[index] = (short)value; } } } }
/** * Returns the pixel's value for all the bands as an array. * * @param x pixel coordinate. * @param y pixel coordinate. * @param storage If not null then the pixel's value is written here. If null a new array is created. * @return The pixel's value. */ public short[] get(int x, int y, short[] storage) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds"); if (storage == null) { storage = new short[numBands]; } int index = getIndex(x, y, 0); for (int i = 0; i < numBands; i++, index++) { storage[i] = data[index]; } return storage; }
public static void vertical( Kernel1D_S32 kernel, InterleavedS16 src, InterleavedI16 dst , int divisor ) { final short[] dataSrc = src.data; final short[] dataDst = dst.data; final int[] dataKer = kernel.data; final int offset = kernel.getOffset(); final int kernelWidth = kernel.getWidth(); final int numBands = src.getNumBands(); final int halfDivisor = divisor/2; 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; int total = 0; for (int k = 0; k < kernelWidth; k++) { total += (dataSrc[indexSrc] )* dataKer[k]; indexSrc += src.stride; } dataDst[indexDst++] = (short)((total+halfDivisor)/divisor); } indexSrcStart += numBands; } } }
output.set(x,y, total);
/** * Rotates the image 90 degrees in the counter-clockwise direction. */ public static void rotateCCW( InterleavedI16 input , InterleavedI16 output ) { if( input.width != output.height || input.height != output.width || input.numBands != output.numBands ) throw new IllegalArgumentException("Incompatible shapes"); int w = input.width-1; for( int y = 0; y < input.height; y++ ) { int indexSrc = input.startIndex + y*input.stride; for (int x = 0; x < input.width; x++) { int indexDst = output.getIndex(y,w-x); int end = indexSrc + input.numBands; while( indexSrc != end ) { output.data[indexDst++] = input.data[indexSrc++]; } } } }