/** * Bounds image pixels to be between these two values * * @param img Image * @param min minimum value. * @param max maximum value. */ public static void boundImage(GrayS8 img , int min , int max ) { final int h = img.getHeight(); final int w = img.getWidth(); byte[] data = img.data; for (int y = 0; y < h; y++) { int index = img.getStartIndex() + y * img.getStride(); int indexEnd = index+w; // for(int x = 0; x < w; x++ ) { for (; index < indexEnd; index++) { int value = data[index]; if( value < min ) data[index] = (byte)min; else if( value > max ) data[index] = (byte)max; } } }
/** * <p> * Converts an {@link boofcv.struct.image.GrayF64} into a {@link boofcv.struct.image.GrayS8}. * </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 GrayS8 convert(GrayF64 input, GrayS8 output) { if (output == null) { output = new GrayS8(input.width, input.height); } else { output.reshape(input.width,input.height); } ImplConvertImage.convert(input, output); return output; }
@Override public Number get(int x, int y) { return image.get(x,y); }
/** * Computes the variance of pixel intensity values inside the image. * * @param img Input image. Not modified. * @param mean Mean pixel intensity value. * @return Pixel variance */ public static double variance( GrayS8 img , double mean ) { double variance = 0; for (int y = 0; y < img.height; y++) { int index = img.getStartIndex() + y * img.getStride(); int indexEnd = index+img.width; // for(int x = 0; x < img.width; x++ ) { for (; index < indexEnd; index++ ) { double d = (img.data[index]) - mean; variance += d*d; } } return variance/(img.width*img.height); }
public static BufferedImage renderOrientation4(GrayS8 direction , GrayF32 intensity , float threshold , BufferedImage out ) { out = new BufferedImage(direction.getWidth(),direction.getHeight(),BufferedImage.TYPE_INT_RGB); int data[] = raster.getDataStorage(); int w = direction.getWidth(); int h = direction.getHeight();
public static void convert( GrayS8 from, GrayI8 to ) { if (from.isSubimage() || to.isSubimage()) { 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 < from.width; x++) { to.data[indexTo++] = ( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; System.arraycopy(from.data, 0, to.data, 0, N); } }
@Override public int unsafe_get(int x, int y) { return data[getIndex(x, y)]; }
suppressed.reshape(input.width,input.height); angle.reshape(input.width,input.height); direction.reshape(input.width,input.height); work.reshape(input.width,input.height);
public static BufferedImage renderOrientation4(GrayS8 direction , GrayF32 intensity , float threshold , BufferedImage out ) { out = new BufferedImage(direction.getWidth(),direction.getHeight(),BufferedImage.TYPE_INT_RGB); int offsetDst = ConvertRaster.getOffset(raster); int w = direction.getWidth(); int h = direction.getHeight();
public static void convert( GrayS8 from, GrayF32 to ) { if (from.isSubimage() || to.isSubimage()) { 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 < from.width; x++) { to.data[indexTo++] = ( float )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( float )( from.data[i] ); } } }
public static <T extends ImageGray<T>> T create(Class<T> type , int width , int height ) { if( type == GrayU8.class) { return (T)new GrayU8(width,height); } else if( type == GrayS8.class) { return (T)new GrayS8(width,height); } else if( type == GrayU16.class) { return (T)new GrayU16(width,height); } else if( type == GrayS16.class) { return (T)new GrayS16(width,height); } else if( type == GrayS32.class) { return (T)new GrayS32(width,height); } else if( type == GrayF32.class) { return (T)new GrayF32(width,height); } else{ throw new IllegalArgumentException("Unknown image type: "+type); } } }
for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); System.arraycopy(from.data,indexFrom,to.data,indexTo,from.width); for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); int indexEndTo = indexTo + from.width; for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); int indexEndTo = indexTo + from.width; for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y);
/** * Adds uniform i.i.d noise to each pixel in the image. Noise range is min ≤ X < max. */ public static void addUniform(GrayS8 input, Random rand , int min , int max) { int range = max-min; byte[] data = input.data; for (int y = 0; y < input.height; y++) { int index = input.getStartIndex() + y * input.getStride(); for (int x = 0; x < input.width; x++) { int value = (data[index] ) + rand.nextInt(range)+min; if( value < -128 ) value = -128; if( value > 127 ) value = 127; data[index++] = (byte) value; } } }
/** * <p> * Computes the absolute value of the difference between each pixel in the two images.<br> * d(x,y) = |img1(x,y) - img2(x,y)| * </p> * @param imgA Input image. Not modified. * @param imgB Input image. Not modified. * @param diff Absolute value of difference image. Modified. */ public static void diffAbs(GrayS8 imgA , GrayS8 imgB , GrayS8 diff ) { InputSanityCheck.checkSameShape(imgA,imgB,diff); final int h = imgA.getHeight(); final int w = imgA.getWidth(); for (int y = 0; y < h; y++) { int indexA = imgA.getStartIndex() + y * imgA.getStride(); int indexB = imgB.getStartIndex() + y * imgB.getStride(); int indexDiff = diff.getStartIndex() + y * diff.getStride(); int indexEnd = indexA+w; // for(int x = 0; x < w; x++ ) { for (; indexA < indexEnd; indexA++, indexB++, indexDiff++ ) { diff.data[indexDiff] = (byte)Math.abs((imgA.data[indexA] ) - (imgB.data[indexB] )); } } }
/** * <p> * Converts an {@link boofcv.struct.image.GrayS32} into a {@link boofcv.struct.image.GrayS8}. * </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 GrayS8 convert(GrayS32 input, GrayS8 output) { if (output == null) { output = new GrayS8(input.width, input.height); } else { output.reshape(input.width,input.height); } ImplConvertImage.convert(input, output); return output; }
public static void convert( GrayS8 from, GrayS32 to ) { if (from.isSubimage() || to.isSubimage()) { 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 < from.width; x++) { to.data[indexTo++] = ( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( from.data[i] ); } } }
public static <T extends ImageGray<T>> T createSingleBand(Class<T> type, int width, int height) { type = BoofTesting.convertGenericToSpecificType(type); if (type == GrayU8.class) { return (T)new GrayU8(width, height); } else if (type == GrayS8.class) { return (T)new GrayS8(width, height); } else if (type == GrayS16.class) { return (T)new GrayS16(width, height); } else if (type == GrayU16.class) { return (T)new GrayU16(width, height); } else if (type == GrayS32.class) { return (T)new GrayS32(width, height); } else if (type == GrayS64.class) { return (T)new GrayS64(width, height); } else if (type == GrayF32.class) { return (T)new GrayF32(width, height); } else if (type == GrayF64.class) { return (T)new GrayF64(width, height); } else if( (Class)type == GrayI.class ) { // ImageInteger is a generic type, so just create something return (T)new GrayS32(width,height); } throw new RuntimeException("Unknown type: "+type.getSimpleName()); }
int dir = direction.get(x,y); int dx,dy;