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 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; } } }
final int imgHeight = dest.getHeight();
final int imgHeight = dest.getHeight();
final int height = src.getHeight();
final int imgHeight = dest.getHeight();
final int height = src.getHeight();
final int imgHeight = dest.getHeight();
/** * 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 image, GrayF64 dest ) { final double[] dataSrc = image.data; final double[] dataDst = dest.data; final double[] dataKer = kernel.data; final int offset = kernel.getOffset(); final int kernelWidth = kernel.getWidth(); final int imgWidth = dest.getWidth(); final int imgHeight = dest.getHeight(); final int yEnd = imgHeight-(kernelWidth-offset-1); for( int y = offset; y < yEnd; y++ ) { int indexDst = dest.startIndex+y*dest.stride; int i = image.startIndex + (y-offset)*image.stride; final int iEnd = i+imgWidth; for( ; i < iEnd; i++ ) { double total = 0; int indexSrc = i; for( int k = 0; k < kernelWidth; k++ ) { total += (dataSrc[indexSrc] )* dataKer[k]; indexSrc += image.stride; } dataDst[indexDst++] = total; } } }
final int imgHeight = output.getHeight();
final int height = input.getHeight();
/** * <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(GrayF64 imgA , GrayF64 imgB , GrayF64 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] = Math.abs((imgA.data[indexA] ) - (imgB.data[indexB] )); } } }
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 ); } } }
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 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++ ) { int startX = x - offset; int endX = startX + kernel.getWidth(); if( startX < 0 ) startX = 0; if( endX > width ) endX = width; int startY = y - offset; int endY = startY + kernel.getWidth(); if( startY < 0 ) startY = 0; if( endY > height ) endY = height; double total = 0; double weight = 0; for( int i = startY; i < endY; i++ ) { for( int j = startX; j < endX; j++ ) { double v = kernel.get(j-x+offset,i-y+offset); total += input.get(j,i)*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] )); } } }
/** * <p> * Performs pixel-wise multiplication<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 multiply(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] )); } } }
/** * <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(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] )); } } }
/** * <p> * Performs pixel-wise division<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 divide(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] )); } } }