/** * 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); } } }
@Override public void set(int x, int y, Number num) { image.set(x,y,num.doubleValue()); }
public static void circshift(GrayF64 a, GrayF64 b ) { int w2 = a.width/2; int h2 = b.height/2; for( int y = 0; y < a.height; y++ ) { int yy = (y+h2)%a.height; for( int x = 0; x < a.width; x++ ) { int xx = (x+w2)%a.width; b.set( xx , yy , a.get(x,y)); } } }
public static void convolve( GrayF64 integral , IntegralKernel kernel, GrayF64 output ) { for( int y = 0; y < integral.height; y++ ) { for( int x = 0; x < integral.width; x++ ) { double total = 0; for( int i = 0; i < kernel.blocks.length; i++ ) { ImageRectangle b = kernel.blocks[i]; total += block_zero(integral,x+b.x0,y+b.y0,x+b.x1,y+b.y1)*kernel.scales[i]; } output.set(x,y,total); } } }
public static void set(ImageGray img, int x, int y, double value) { if (GrayI.class.isAssignableFrom(img.getClass())) { ((GrayI)img).set(x,y,(int)value); } else if (img instanceof GrayF32) { ((GrayF32) img).set(x, y,(float)value); } else if (img instanceof GrayF64) { ((GrayF64) img).set(x, y, value); } else if (img instanceof GrayS64) { ((GrayS64) img).set(x, y, (long)value); } else { throw new IllegalArgumentException("Unknown or incompatible image type: " + img.getClass().getSimpleName()); } }
@Override public void setOutside(int x, int y, double val) { image.set(colWrap.getIndex(x) , rowWrap.getIndex(y),val); } }
public void set( int x , int y , double val ) { if( image.isInBounds(x,y) ) image.set(x,y,val); setOutside(x,y,val); }
total += block_zero(integral,x+b.x0,y+b.y0,x+b.x1,y+b.y1)*kernel.scales[i]; output.set(x,y,total); total += block_zero(integral,x+b.x0,y+b.y0,x+b.x1,y+b.y1)*kernel.scales[i]; output.set(x,y,total); total += block_zero(integral,x+b.x0,y+b.y0,x+b.x1,y+b.y1)*kernel.scales[i]; output.set(x,y,total); total += block_zero(integral,x+b.x0,y+b.y0,x+b.x1,y+b.y1)*kernel.scales[i]; output.set(x,y,total);
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 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 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 ); } } }