/** * <p> * Converts an {@link boofcv.struct.image.InterleavedS32} into a {@link boofcv.struct.image.InterleavedS64}. * </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 InterleavedS64 convert(InterleavedS32 input, InterleavedS64 output) { if (output == null) { output = new InterleavedS64(input.width, input.height, input.numBands); } else { output.reshape(input.width,input.height,input.numBands); } ImplConvertImage.convert(input, output); return output; }
public static void convert( InterleavedS64 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] ); } } }
/** * 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(InterleavedS64 input, int band , long 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] = value; } } }
/** * 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, long... value) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds"); unsafe_set(x,y,value); }
public void get( int x , int y , long[] pixel ) { if( image.isInBounds(x,y) ) { image.unsafe_get(x, y, pixel); } else { getOutside(x, y, pixel); } }
public static void convert( InterleavedS8 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++] = ( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( from.data[i] ); } } }
/** * Returns the value of the specified band in the specified pixel. * * @param x pixel coordinate. * @param y pixel coordinate. * @param band which color band in the pixel * @return an intensity value. */ public long getBand(int x, int y, int band) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds."); if (band < 0 || band >= numBands) throw new ImageAccessException("Invalid band requested."); return data[getIndex(x, y, band)]; }
public static void average( InterleavedS64 from , GrayS64 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);
public void unsafe_get(int x, int y, long[] storage) { int index = getIndex(x, y, 0); for (int i = 0; i < numBands; i++, index++) { storage[i] = data[index]; } }
@Override public void getF(int index, float[] value) { for( int i = 0; i < image.getNumBands(); i++ ) { value[i] = image.data[index++]; } }
@Override public InterleavedS64 createNew(int imgWidth, int imgHeight) { if (imgWidth == -1 || imgHeight == -1) return new InterleavedS64(); return new InterleavedS64(imgWidth, imgHeight, numBands); } }
((InterleavedS32) img).setBand(x, y, band, (int) value); } else if (img instanceof InterleavedS64) { ((InterleavedS64) img).setBand(x, y, band, (long) value); } else if (img instanceof InterleavedF32) { ((InterleavedF32) img).setBand(x, y, band, (float) value);
public static double get(ImageInterleaved img, int x, int y , int band ) { if (img instanceof InterleavedU8) { return ((InterleavedU8) img).getBand(x, y, band); } else if (img instanceof InterleavedS8) { return ((InterleavedS8) img).getBand(x, y, band); } else if (img instanceof InterleavedS16) { return ((InterleavedS16) img).getBand(x, y, band); } else if (img instanceof InterleavedU16) { return ((InterleavedU16) img).getBand(x, y, band); } else if (img instanceof InterleavedS32) { return ((InterleavedS32) img).getBand(x, y, band); } else if (img instanceof InterleavedS64) { return ((InterleavedS64) img).getBand(x, y, band); } else if (img instanceof InterleavedF32) { return ((InterleavedF32) img).getBand(x, y, band); } else if (img instanceof InterleavedF64) { return ((InterleavedF64) img).getBand(x, y, band); } else { throw new IllegalArgumentException("Unknown or incompatible image type: " + img.getClass().getSimpleName()); } }
public static void convert( InterleavedU8 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++] = ( from.data[indexFrom++] & 0xFF); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( from.data[i] & 0xFF); } } }
public void set( int x , int y , long[] pixel ) { if (image.isInBounds(x, y)) { image.unsafe_set(x, y, pixel); } else { setOutside(x, y, pixel); } }
/** * 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 long[] get(int x, int y, long[] storage) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds"); if (storage == null) { storage = new long[numBands]; } unsafe_get(x,y,storage); return storage; }
/** * Returns the value of the specified band in the specified pixel. * * @param x pixel coordinate. * @param y pixel coordinate. * @param band which color band in the pixel * @param value The new value of the element. */ public void setBand(int x, int y, int band, long value) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds."); if (band < 0 || band >= numBands) throw new ImageAccessException("Invalid band requested."); data[getIndex(x, y, band)] = value; }
public void unsafe_set(int x, int y, long... value) { int index = getIndex(x, y, 0); for (int i = 0; i < numBands; i++, index++) { data[index] = value[i]; } }
@Override public void setF(int index, float[] value) { for( int i = 0; i < image.getNumBands(); i++ ) { image.data[index++] = (long)value[i]; } }
public static <T extends ImageInterleaved<T>> T createInterleaved(Class<T> type, int width, int height , int numBands) { type = BoofTesting.convertGenericToSpecificType(type); if (type == InterleavedU8.class) { return (T)new InterleavedU8(width, height,numBands); } else if (type == InterleavedS8.class) { return (T)new InterleavedS8(width, height,numBands); } else if (type == InterleavedU16.class) { return (T)new InterleavedU16(width, height,numBands); } else if (type == InterleavedS16.class) { return (T)new InterleavedS16(width, height,numBands); } else if (type == InterleavedS32.class) { return (T)new InterleavedS32(width, height,numBands); } else if (type == InterleavedS64.class) { return (T)new InterleavedS64(width, height,numBands); } else if (type == InterleavedF32.class) { return (T)new InterleavedF32(width, height,numBands); } else if (type == InterleavedF64.class) { return (T)new InterleavedF64(width, height,numBands); } else if( (Class)type == ImageInterleaved.class ) { // ImageInteger is a generic type, so just create something return (T)new InterleavedS32(width,height,numBands); } throw new RuntimeException("Unknown type: "+type.getSimpleName()); }