/** * 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(GrayS32 img, int 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.intValue()); }
public static void convolve( GrayS32 integral , IntegralKernel kernel, GrayS32 output ) { for( int y = 0; y < integral.height; y++ ) { for( int x = 0; x < integral.width; x++ ) { int 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); } } }
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 GrayS32 convertToImage(Kernel2D_S32 kernel ) { int w = kernel.getWidth(); GrayS32 ret = new GrayS32(w,w); for( int i = 0; i < w; i++ ) { for( int j = 0; j < w; j++ ) { ret.set(j,i,kernel.get(j,i)); } } return ret; }
public static void vertical(Kernel1D_S32 kernel, GrayS32 input, GrayS32 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 total = 0; int 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++ ) { int v = kernel.get(i-y+offset); total += input.get(x,i)*v; weight += v; } output.set(x,y, (total+weight/2)/weight ); } } }
public static void horizontal(Kernel1D_S32 kernel, GrayS32 input, GrayS32 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 total = 0; int 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++ ) { int v = kernel.get(j-x+offset); total += input.get(j,y)*v; weight += v; } output.set(x,y, (total+weight/2)/weight ); } } }
public static void convolve(Kernel2D_S32 kernel, GrayS32 input, GrayS32 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; int total = 0; int weight = 0; for( int i = startY; i < endY; i++ ) { for( int j = startX; j < endX; j++ ) { int v = kernel.get(j-x+offset,i-y+offset); total += input.get(j,i)*v; weight += v; } } output.set(x,y, (total+weight/2)/weight ); } } }