@Override public Number get(int x, int y) { return image.get(x,y); }
/** * <p> * Converts an {@link boofcv.struct.image.GrayS8} into a {@link boofcv.struct.image.GrayF64}. * </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 GrayF64 convert(GrayS8 input, GrayF64 output) { if (output == null) { output = new GrayF64(input.width, input.height); } else { output.reshape(input.width,input.height); } ImplConvertImage.convert(input, output); return output; }
/** * Flips the image from top to bottom */ public static void flipVertical( GrayF64 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 ) { double tmp = input.data[index1]; input.data[index1++] = input.data[index2]; input.data[index2++] = (double)tmp; } } }
/** * Bounds image pixels to be between these two values * * @param img Image * @param min minimum value. * @param max maximum value. */ public static void boundImage(GrayF64 img , double min , double max ) { final int h = img.getHeight(); final int w = img.getWidth(); double[] 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++) { double value = data[index]; if( value < min ) data[index] = min; else if( value > max ) data[index] = max; } } }
public static void vertical(Kernel1D_F64 kernel, GrayF64 input, GrayF64 output ) { final int offset = kernel.getOffset(); final int width = input.getWidth(); final int height = input.getHeight(); for (int y = 0; y < height; y++) { for( int x = 0; x < width; x++ ) { double total = 0; double 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++ ) { double v = kernel.get(i-y+offset); total += input.get(x,i)*v; weight += v; } output.set(x,y, total/weight ); } } }
public static void convolve( Kernel2D_F64 kernel , GrayF64 src , GrayF64 dest ) { final double[] dataKernel = kernel.data; final double[] dataSrc = src.data; final double[] dataDst = dest.data; final int width = src.getWidth(); final int height = src.getHeight(); int offsetL = kernel.offset; int offsetR = kernel.width-kernel.offset-1; for( int y = offsetL; y < height-offsetR; y++ ) { int indexDst = dest.startIndex + y*dest.stride+offsetL; for( int x = offsetL; x < width-offsetR; x++ ) { double total = 0; int indexKer = 0; for( int ki = 0; ki < kernel.width; ki++ ) { int indexSrc = src.startIndex + (y+ki-offsetL)*src.stride + x-offsetL; for( int kj = 0; kj < kernel.width; kj++ ) { total += (dataSrc[indexSrc+kj] )* dataKernel[indexKer++]; } } dataDst[indexDst++] = total; } } }
public static void convert( GrayS16 from, GrayF64 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++] = ( double )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( double )( from.data[i] ); } } }
public double get( int x , int y ) { if( image.isInBounds(x,y) ) return image.get(x,y); return getOutside( x , y ); }
protected void resizeImages( int workRegionSize ) { templateNew.reshape(workRegionSize, workRegionSize); template.reshape(workRegionSize, workRegionSize); cosine.reshape(workRegionSize,workRegionSize); k.reshape(workRegionSize,workRegionSize); kf.reshape(workRegionSize,workRegionSize); alphaf.reshape(workRegionSize,workRegionSize); newAlphaf.reshape(workRegionSize,workRegionSize); response.reshape(workRegionSize,workRegionSize); tmpReal0.reshape(workRegionSize,workRegionSize); tmpReal1.reshape(workRegionSize,workRegionSize); tmpFourier0.reshape(workRegionSize,workRegionSize); tmpFourier1.reshape(workRegionSize,workRegionSize); tmpFourier2.reshape(workRegionSize,workRegionSize); gaussianWeight.reshape(workRegionSize,workRegionSize); gaussianWeightDFT.reshape(workRegionSize,workRegionSize); }
/** * Draws a filled rectangle that is aligned along the image axis inside the image. * * @param img Image the rectangle is drawn in. Modified * @param value Value of the rectangle * @param x0 Top left x-coordinate * @param y0 Top left y-coordinate * @param width Rectangle width * @param height Rectangle height */ public static void fillRectangle(GrayF64 img, double value, int x0, int y0, int width, int height) { int x1 = x0 + width; int y1 = y0 + height; if( x0 < 0 ) x0 = 0; if( x1 > img.width ) x1 = img.width; if( y0 < 0 ) y0 = 0; if( y1 > img.height ) y1 = img.height; for (int y = y0; y < y1; y++) { for (int x = x0; x < x1; x++) { img.set(x, y, value); } } }
public void set( int x , int y , double val ) { if( image.isInBounds(x,y) ) image.set(x,y,val); setOutside(x,y,val); }
@Override public double unsafe_getD(int x, int y) { return image.data[image.getIndex(x, y)]; }
public static void horizontal(Kernel1D_F64 kernel, GrayF64 input, GrayF64 output ) { final int offset = kernel.getOffset(); final int width = input.getWidth(); final int height = input.getHeight(); for (int y = 0; y < height; y++) { for( int x = 0; x < width; x++ ) { double total = 0; double weight = 0; int startX = x - offset; int endX = startX+kernel.getWidth(); if( startX < 0 ) startX = 0; if( endX > width ) endX = width; for( int j = startX; j < endX; j++ ) { double v = kernel.get(j-x+offset); total += input.get(j,y)*v; weight += v; } output.set(x,y, total/weight ); } } }
/** * <p> * Performs pixel-wise addition<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 add(GrayF64 imgA , GrayF64 imgB , GrayF64 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] = ((imgA.data[indexA] ) + (imgB.data[indexB] )); } } }
public static void vertical3( Kernel1D_F64 kernel , GrayF64 image, GrayF64 dest ) { final double[] dataSrc = image.data; final double[] dataDst = dest.data; final double k1 = kernel.data[0]; final double k2 = kernel.data[1]; final double k3 = kernel.data[2]; final int radius = kernel.getRadius(); final int imgWidth = dest.getWidth(); final int imgHeight = dest.getHeight(); final int yEnd = imgHeight-radius; for( int y = radius; y < yEnd; y++ ) { int indexDst = dest.startIndex+y*dest.stride; int i = image.startIndex + (y-radius)*image.stride; final int iEnd = i+imgWidth; for( ; i < iEnd; i++ ) { int indexSrc = i; double total = (dataSrc[indexSrc]) * k1; indexSrc += image.stride; total += (dataSrc[indexSrc])*k2; indexSrc += image.stride; total += (dataSrc[indexSrc])*k3; dataDst[indexDst++] = total; } } }
public static void convert( GrayS64 from, GrayF64 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++] = ( double )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( double )( from.data[i] ); } } }
/** * Flips the image from left to right */ public static void flipHorizontal( GrayF64 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 ) { double tmp = input.data[index1]; input.data[index1++] = input.data[index2]; input.data[index2--] = (double)tmp; } } }