/** * Converts a {@link Planar} into a {@link ImageGray} by computing the average value of each pixel * across all the bands. * * @param input Input Planar image that is being converted. Not modified. * @param output (Optional) The single band output image. If null a new image is created. Modified. * @return Converted image. */ public static GrayS64 average( Planar<GrayS64> input , GrayS64 output ) { if (output == null) { output = new GrayS64(input.width, input.height); } else { output.reshape(input.width,input.height); } ImplConvertPlanarToGray.average(input, output); return output; }
public long get( int x , int y ) { if( image.isInBounds(x,y) ) return image.get(x,y); return getOutside( x , y ); }
/** * Bounds image pixels to be between these two values * * @param img Image * @param min minimum value. * @param max maximum value. */ public static void boundImage(GrayS64 img , long min , long max ) { final int h = img.getHeight(); final int w = img.getWidth(); long[] 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++) { long value = data[index]; if( value < min ) data[index] = min; else if( value > max ) data[index] = max; } } }
/** * Flips the image from left to right */ public static void flipHorizontal( GrayS64 input ) { int w2 = input.width/2; for( int y = 0; y < input.height; y++ ) { int index1 = input.getStartIndex() + y * input.getStride(); int index2 = index1 + input.width-1; int end = index1 + w2; while( index1 < end ) { long tmp = input.data[index1]; input.data[index1++] = input.data[index2]; input.data[index2--] = (long)tmp; } } }
/** * Sets the value of the specified pixel. * * @param x pixel coordinate. * @param y pixel coordinate. * @param value The pixel's new value. */ 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 static void convert( GrayU8 from, GrayS64 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++] & 0xFF); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( from.data[i] & 0xFF); } } }
/** * Returns the value of the specified pixel. * * @param x pixel coordinate. * @param y pixel coordinate. * @return Pixel intensity value. */ public long get(int x, int y) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds"); return unsafe_get(x,y); }
public void set( int x , int y , long value ) { if( image.isInBounds(x,y) ) image.set(x,y,value); setOutside( x , y , value); }
@Override public Number get(int x, int y) { return image.get(x,y); }
public long unsafe_get(int x, int y) { return data[getIndex(x, y)]; }
public static void convert( GrayS8 from, GrayS64 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] ); } } }
/** * Flips the image from top to bottom */ public static void flipVertical( GrayS64 input ) { int h2 = input.height/2; for( int y = 0; y < h2; y++ ) { int index1 = input.getStartIndex() + y * input.getStride(); int index2 = input.getStartIndex() + (input.height - y - 1) * input.getStride(); int end = index1 + input.width; while( index1 < end ) { long tmp = input.data[index1]; input.data[index1++] = input.data[index2]; input.data[index2++] = (long)tmp; } } }
/** * Constructor which specifies the input image type. * * @param imageType Either {@link GrayU8} or {@link GrayF32} */ public TldVarianceFilter( Class<T> imageType ) { // declare integral images. if(GeneralizedImageOps.isFloatingPoint(imageType) ) { integral = new GrayF32(1,1); integralSq = new GrayF64(1,1); } else { integral = new GrayS32(1,1); integralSq = new GrayS64(1,1); } }
@Override public long getOutside(int x, int y) { return image.get( colWrap.getIndex(x) , rowWrap.getIndex(y) ); }
public void unsafe_set(int x, int y, long value) { data[getIndex(x, y)] = value; }
/** * <p> * Converts an {@link boofcv.struct.image.GrayS16} into a {@link boofcv.struct.image.GrayS64}. * </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 GrayS64 convert(GrayS16 input, GrayS64 output) { if (output == null) { output = new GrayS64(input.width, input.height); } else { output.reshape(input.width,input.height); } ImplConvertImage.convert(input, output); return output; }
/** * <p> * Performs pixel-wise subtraction.<br> * output(x,y) = imgA(x,y) - imgB(x,y) * </p> * @param imgA Input image. Not modified. * @param imgB Input image. Not modified. * @param output Output image. Modified. */ public static void subtract(GrayS64 imgA , GrayS64 imgB , GrayS64 output ) { InputSanityCheck.checkSameShape(imgA,imgB,output); 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 indexOut = output.getStartIndex() + y * output.getStride(); int indexEnd = indexA+w; // for(int x = 0; x < w; x++ ) { for (; indexA < indexEnd; indexA++, indexB++, indexOut++ ) { output.data[indexOut] = (long)((imgA.data[indexA] ) - (imgB.data[indexB] )); } } }
public static void convert( GrayU16 from, GrayS64 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++] & 0xFFFF); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( from.data[i] & 0xFFFF); } } }