private static void _renderLabeled(GrayS32 labelImage, BufferedImage out, int[] colors) { int w = labelImage.getWidth(); int h = labelImage.getHeight(); for( int y = 0; y < h; y++ ) { int indexSrc = labelImage.startIndex + y*labelImage.stride; for( int x = 0; x < w; x++ ) { int rgb = colors[labelImage.data[indexSrc++]]; out.setRGB(x,y,rgb); } } }
private static void _renderLabeled(GrayS32 labelImage, BufferedImage out, int[] colors) { int w = labelImage.getWidth(); int h = labelImage.getHeight(); for( int y = 0; y < h; y++ ) { int indexSrc = labelImage.startIndex + y*labelImage.stride; for( int x = 0; x < w; x++ ) { int rgb = colors[labelImage.data[indexSrc++]]; out.setRGB(x,y,rgb); } } }
public static void horizontal3(Kernel1D_S32 kernel , GrayS32 image, GrayS32 dest , int divisor ) { final int[] dataSrc = image.data; final int[] dataDst = dest.data; final int k1 = kernel.data[0]; final int k2 = kernel.data[1]; final int k3 = kernel.data[2]; final int radius = kernel.getRadius(); final int width = image.getWidth(); final int halfDivisor = divisor/2; for( int i = 0; i < image.height; i++ ) { int indexDst = dest.startIndex + i*dest.stride+radius; int j = image.startIndex + i*image.stride - radius; final int jEnd = j+width-radius; for( j += radius; j < jEnd; j++ ) { int indexSrc = j; int total = (dataSrc[indexSrc++])*k1; total += (dataSrc[indexSrc++])*k2; total += (dataSrc[indexSrc])*k3; dataDst[indexDst++] = ((total+halfDivisor)/divisor); } } }
public static void horizontal5(Kernel1D_S32 kernel , GrayS32 image, GrayS32 dest ) { final int[] dataSrc = image.data; final int[] dataDst = dest.data; final int k1 = kernel.data[0]; final int k2 = kernel.data[1]; final int k3 = kernel.data[2]; final int k4 = kernel.data[3]; final int k5 = kernel.data[4]; final int radius = kernel.getRadius(); final int width = image.getWidth(); for( int i = 0; i < image.height; i++ ) { int indexDst = dest.startIndex + i*dest.stride+radius; int j = image.startIndex + i*image.stride - radius; final int jEnd = j+width-radius; for( j += radius; j < jEnd; j++ ) { int indexSrc = j; int total = (dataSrc[indexSrc++])*k1; total += (dataSrc[indexSrc++])*k2; total += (dataSrc[indexSrc++])*k3; total += (dataSrc[indexSrc++])*k4; total += (dataSrc[indexSrc])*k5; dataDst[indexDst++] = total; } } }
public static void horizontal3(Kernel1D_S32 kernel , GrayS32 image, GrayS32 dest ) { final int[] dataSrc = image.data; final int[] dataDst = dest.data; final int k1 = kernel.data[0]; final int k2 = kernel.data[1]; final int k3 = kernel.data[2]; final int radius = kernel.getRadius(); final int width = image.getWidth(); for( int i = 0; i < image.height; i++ ) { int indexDst = dest.startIndex + i*dest.stride+radius; int j = image.startIndex + i*image.stride - radius; final int jEnd = j+width-radius; for( j += radius; j < jEnd; j++ ) { int indexSrc = j; int total = (dataSrc[indexSrc++])*k1; total += (dataSrc[indexSrc++])*k2; total += (dataSrc[indexSrc])*k3; dataDst[indexDst++] = total; } } }
private static void renderLabeled(GrayS32 labelImage, int[] colors, IntegerInterleavedRaster raster) { int rasterIndex = 0; int data[] = raster.getDataStorage(); int w = labelImage.getWidth(); int h = labelImage.getHeight(); for( int y = 0; y < h; y++ ) { int indexSrc = labelImage.startIndex + y*labelImage.stride; for( int x = 0; x < w; x++ ) { data[rasterIndex++] = colors[labelImage.data[indexSrc++]]; } } }
private static void renderLabeled(GrayS32 labelImage, int[] colors, DataBufferInt buffer, WritableRaster raster) { int rasterIndex = 0; int data[] = buffer.getData(); int w = labelImage.getWidth(); int h = labelImage.getHeight(); for( int y = 0; y < h; y++ ) { int indexSrc = labelImage.startIndex + y*labelImage.stride; for( int x = 0; x < w; x++ ) { data[rasterIndex++] = colors[labelImage.data[indexSrc++]]; } } }
public static BufferedImage renderLabeled(GrayS32 labelImage, int colors[], BufferedImage out) { if( out == null ) { out = new BufferedImage(labelImage.getWidth(),labelImage.getHeight(),BufferedImage.TYPE_INT_RGB); } try { if( out.getRaster() instanceof IntegerInterleavedRaster) { renderLabeled(labelImage, colors, (IntegerInterleavedRaster)out.getRaster()); } else { _renderLabeled(labelImage, out, colors); } // hack so that it knows the image has been modified out.setRGB(0,0,out.getRGB(0,0)); } catch( SecurityException e ) { _renderLabeled(labelImage, out, colors); } return out; }
public static BufferedImage renderLabeled(GrayS32 labelImage, int colors[], BufferedImage out) { if( out == null ) { out = new BufferedImage(labelImage.getWidth(),labelImage.getHeight(),BufferedImage.TYPE_INT_RGB); } WritableRaster raster = out.getRaster(); DataBuffer buffer = raster.getDataBuffer(); try { if( buffer.getDataType() == DataBuffer.TYPE_INT) { renderLabeled(labelImage, colors, (DataBufferInt)buffer,raster); } else { _renderLabeled(labelImage, out, colors); } // hack so that it knows the image has been modified out.setRGB(0,0,out.getRGB(0,0)); } catch( SecurityException e ) { _renderLabeled(labelImage, out, colors); } return out; }
public static void horizontal( Kernel1D_S32 kernel , GrayS32 image, GrayS32 dest ) { final int[] dataSrc = image.data; final int[] dataDst = dest.data; final int[] dataKer = kernel.data; final int offset = kernel.getOffset(); final int kernelWidth = kernel.getWidth(); final int width = image.getWidth(); for( int i = 0; i < image.height; i++ ) { int indexDst = dest.startIndex + i*dest.stride+offset; int j = image.startIndex + i*image.stride; final int jEnd = j+width-(kernelWidth-1); for( ; j < jEnd; j++ ) { int total = 0; int indexSrc = j; for( int k = 0; k < kernelWidth; k++ ) { total += (dataSrc[indexSrc++] ) * dataKer[k]; } dataDst[indexDst++] = total; } } }
public static void horizontal( Kernel1D_S32 kernel , GrayS32 image, GrayS32 dest , int divisor ) { final int[] dataSrc = image.data; final int[] dataDst = dest.data; final int[] dataKer = kernel.data; final int offset = kernel.getOffset(); final int kernelWidth = kernel.getWidth(); final int halfDivisor = divisor/2; final int width = image.getWidth(); for( int i = 0; i < image.height; i++ ) { int indexDst = dest.startIndex + i*dest.stride+offset; int j = image.startIndex + i*image.stride; final int jEnd = j+width-(kernelWidth-1); for( ; j < jEnd; j++ ) { int total = 0; int indexSrc = j; for( int k = 0; k < kernelWidth; k++ ) { total += (dataSrc[indexSrc++] ) * dataKer[k]; } dataDst[indexDst++] = ((total+halfDivisor)/divisor); } } }
public static void vertical3(Kernel1D_S32 kernel , GrayS32 image, GrayS32 dest ) { final int[] dataSrc = image.data; final int[] dataDst = dest.data; final int k1 = kernel.data[0]; final int k2 = kernel.data[1]; final int 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; int total = (dataSrc[indexSrc]) * k1; indexSrc += image.stride; total += (dataSrc[indexSrc])*k2; indexSrc += image.stride; total += (dataSrc[indexSrc])*k3; dataDst[indexDst++] = total; } } }
public ImageBinaryLabeledPanel(GrayS32 labelImage, int maxValues , long randSeed ) { this(); this.labelImage = labelImage; img = new BufferedImage(labelImage.getWidth(), labelImage.getHeight(),BufferedImage.TYPE_INT_RGB); setPreferredSize(new Dimension(labelImage.getWidth(), labelImage.getHeight())); setMinimumSize(getPreferredSize()); setMaximumSize(getPreferredSize()); Random rand = new Random(randSeed); colors = BinaryImageOps.selectRandomColors(maxValues,rand); VisualizeBinaryData.renderLabeled(labelImage, colors, img); }
public ImageBinaryLabeledPanel(GrayS32 labelImage, int maxValues , long randSeed ) { this(); this.labelImage = labelImage; img = new BufferedImage(labelImage.getWidth(), labelImage.getHeight(),BufferedImage.TYPE_INT_RGB); setPreferredSize(new Dimension(labelImage.getWidth(), labelImage.getHeight())); setMinimumSize(getPreferredSize()); setMaximumSize(getPreferredSize()); Random rand = new Random(randSeed); colors = BinaryImageOps.selectRandomColors(maxValues,rand); VisualizeBinaryData.renderLabeled(labelImage, colors, img); }
public static void vertical( Kernel1D_S32 kernel, GrayU8 image, GrayS32 dest ) { final byte[] dataSrc = image.data; final int[] dataDst = dest.data; final int[] 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++ ) { int total = 0; int indexSrc = i; for( int k = 0; k < kernelWidth; k++ ) { total += (dataSrc[indexSrc] & 0xFF)* dataKer[k]; indexSrc += image.stride; } dataDst[indexDst++] = total; } } }
/** * Bounds image pixels to be between these two values * * @param img Image * @param min minimum value. * @param max maximum value. */ public static void boundImage(GrayS32 img , int min , int max ) { final int h = img.getHeight(); final int w = img.getWidth(); int[] 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++) { int value = data[index]; if( value < min ) data[index] = min; else if( value > max ) data[index] = max; } } }
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 ); } } }
/** * <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(GrayS32 imgA , GrayS32 imgB , GrayS32 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] = (int)((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(GrayS32 imgA , GrayS32 imgB , GrayS32 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] = (int)((imgA.data[indexA] ) - (imgB.data[indexB] )); } } }