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); } } }
@Override public double unsafe_getD(int x, int y) { return image.unsafe_get(x,y); }
/** * <p> * Converts an {@link boofcv.struct.image.GrayF32} into a {@link boofcv.struct.image.GrayS32}. * </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 GrayS32 convert(GrayF32 input, GrayS32 output) { if (output == null) { output = new GrayS32(input.width, input.height); } else { output.reshape(input.width,input.height); } ImplConvertImage.convert(input, output); return output; }
/** * 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; } } }
@Override public void mouseClicked(MouseEvent e) { if( labelImage.isInBounds(e.getX(),e.getY()) ) { int val = labelImage.get(e.getX(),e.getY()); System.out.println("Label at ("+e.getX()+","+e.getY()+") = "+val); } }
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 vertical(Kernel1D_S32 kernelX, Kernel1D_S32 kernelY, GrayS32 input, GrayI16 output ) { final int offsetX = kernelX.getOffset(); final int offsetY = kernelY.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 weightY = 0; int startY = y - offsetY; int endY = startY + kernelY.getWidth(); if (startY < 0) startY = 0; if (endY > height) endY = height; for (int i = startY; i < endY; i++) { int v = kernelY.get(i - y + offsetY); total += input.get(x, i) * v; weightY += v; } int kerX0 = Math.max(0, offsetX - x); int kerX1 = Math.min(kernelX.getWidth(), width - x + offsetX); int weightX = 0; for (int i = kerX0; i < kerX1; i++) { weightX += kernelX.get(i); } int weight = weightX * weightY; output.set(x,y, (total+weight/2)/weight ); } } }
int inputLabel = input.unsafe_get(x, y); int outputLabel = output.unsafe_get(x, y); output.unsafe_set(x,y,outputLabel); regionMemberCount.add(1); mergeList.add(outputLabel); if( !input.isInBounds(x+offset.x,y+offset.y)) continue; if( inputLabel == input.unsafe_get(x+offset.x,y+offset.y) ) { int outputAdj = output.unsafe_get(x+offset.x,y+offset.y); if( outputAdj == -1 ) { // see if not assigned regionMemberCount.data[outputLabel]++; output.unsafe_set(x+offset.x,y+offset.y, outputLabel); } else if( outputLabel != outputAdj ) { // see if assigned to different regions markMerge(outputLabel,outputAdj); inputLabel = input.unsafe_get(x, y); outputLabel = output.unsafe_get(x, y); output.unsafe_set(x,y,outputLabel); regionMemberCount.add(1); mergeList.add(outputLabel); if( !input.isInBounds(x+offset.x,y+offset.y)) continue; if( inputLabel == input.unsafe_get(x+offset.x,y+offset.y) ) {
for (int y = 0; y < segments.height; y++) { for (int x = 0; x < segments.width; x++) { int index = segments.unsafe_get(x, y); if (index == 0) output.setRGB(x, y, 0xFF0000); for (int y = 0; y < segments.height; y++) { for (int x = 0; x < segments.width; x++) { int index = segments.unsafe_get(x, y); if (index == 0) { for (int i = -radius; i <= radius; i++) { int xx = x + j; if (segments.isInBounds(xx, yy)) { output.setRGB(xx, yy, 0xFF0000);
public static void convert( GrayS8 from, GrayS32 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++] = ( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( from.data[i] ); } } }
@Override public GrayS32 transform(T original, GrayS32 transformed) { if( transformed == null ) { ImageDimension d = UtilWavelet.transformDimension(original,numLevels); transformed = new GrayS32(d.width,d.height); } temp.reshape(transformed.width,transformed.height); copyInput.reshape(original.width,original.height); if( original.getDataType().getDataType() == int.class ) { copyInput.setTo((GrayS32)original); } else { GConvertImage.convert(original, copyInput); } WaveletTransformOps.transformN(desc, copyInput,transformed,temp,numLevels); return transformed; }
storage = InputSanityCheck.checkDeclare(output, storage); storage = storage.subimage(0,0,output.width,output.height, null); storage.subImage = false; height += height%2; input = input.subimage(0,0,width,height, null); output = output.subimage(0,0,width,height, null); input.setTo(output); storage.reshape(width,height); transform1(desc,input,output,storage);
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); } } }
/** * Specifies the image's intrinsic parameters and target size * * @param width Width of the input image * @param height Height of the input image */ private void configure( int width , int height ) { // resize storage images labeled.reshape(width, height); // adjust size based parameters based on image size this.minimumContour = (int)(width*minContourFraction); this.minimumArea = Math.pow(this.minimumContour /4.0,2); if( helper != null ) helper.setImageShape(width,height); }
@Override public Number get(int x, int y) { return image.get(x,y); }
/** * Examines pixels along the bottom border */ protected void connectBottom(GrayS32 input, GrayS32 output) { for( int x = 0; x < input.width-1; x++ ) { int y = input.height-1; int inputLabel = input.unsafe_get(x,y); int outputLabel = output.unsafe_get(x,y); if( outputLabel == -1 ) { // see if it needs to create a new output segment outputLabel = regionMemberCount.size; output.unsafe_set(x,y,outputLabel); regionMemberCount.add(1); mergeList.add(outputLabel); } // for 4 and 8 connect the check is only +1 x and 0 y if( inputLabel == input.unsafe_get(x+1,y) ) { int outputAdj = output.unsafe_get(x+1,y); if( outputAdj == -1 ) { // see if not assigned regionMemberCount.data[outputLabel]++; output.unsafe_set(x+1,y, outputLabel); } else if( outputLabel != outputAdj ) { // see if assigned to different regions markMerge(outputLabel,outputAdj); } // do nothing, same input and output labels } } } }
/** * Sets the value of the specified pixel. * * @param x pixel coordinate. * @param y pixel coordinate. * @param value The pixel's new value. */ @Override public void set(int x, int y, int value) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds"); data[getIndex(x, y)] = value; }
@Override public void invert(GrayS32 transformed, T original) { copyInput.reshape(transformed.width,transformed.height); temp.reshape(transformed.width,transformed.height); copyInput.setTo(transformed); if( original.getDataType().getDataType() == int.class ) { WaveletTransformOps. inverseN(desc, copyInput, (GrayS32) original, temp, numLevels, minPixelValue, maxPixelValue); } else { copyOutput.reshape(original.width,original.height); WaveletTransformOps.inverseN(desc, copyInput, copyOutput,temp,numLevels,minPixelValue,maxPixelValue); GConvertImage.convert(copyOutput,original); } }
if( isLarger && xx >= input.width ) continue; scale += input.get(xx,y)*alpha[i]; if( isLarger && xx >= input.width ) continue; wavelet += input.get(xx,y)*beta[i]; output.set(outX,y,scale); output.set(output.width/2 + outX , y , wavelet ); if( isLarger && xx >= input.width ) continue; scale += input.get(xx,y)*alpha[i]; if( isLarger && xx >= input.width ) continue; wavelet += input.get(xx,y)*beta[i]; wavelet = 2*wavelet/coefficients.denominatorWavelet; output.set(outX,y,scale); output.set(output.width/2 + outX , y , wavelet );