/** * prepares all data structures */ protected void initalize(T input) { this.input = input; pixels.resize(input.width * input.height); initialSegments.reshape(input.width, input.height); // number of usable pixels that cluster centers can be placed in int numberOfUsable = (input.width-2*BORDER)*(input.height-2*BORDER); gridInterval = (int)Math.sqrt( numberOfUsable/(double)numberOfRegions); if( gridInterval <= 0 ) throw new IllegalArgumentException("Too many regions for an image of this size"); // See equation (1) adjustSpacial = m/gridInterval; }
/** * 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); }
public void process(final BufferedImage input) { setInputImage(input); this.inputImage = input; color.reshape(input.getWidth(),input.getHeight()); pixelToRegion.reshape(color.width, color.height); ConvertBufferedImage.convertFrom(input, color,true); if( input.getWidth() != outColor.getWidth() || input.getHeight() != outColor.getHeight()) { outColor = new BufferedImage(color.width,color.height,BufferedImage.TYPE_INT_RGB); outSegments = new BufferedImage(color.width,color.height,BufferedImage.TYPE_INT_RGB); outBorder = new BufferedImage(color.width,color.height,BufferedImage.TYPE_INT_RGB); } SwingUtilities.invokeLater(new Runnable() { public void run() { gui.setPreferredSize(new Dimension(color.getWidth(), color.getHeight())); gui.setImage(input); gui.revalidate(); processImage = true; } }); doRefreshAll(); }
@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); } }
/** * <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; }
/** * Converts a {@link Planar} into a {@link ImageGray} by computing the average value of each pixel * across all the bands. * * @param input Input Planar image that is being converted. Not modified. * @param output (Optional) The single band output image. If null a new image is created. Modified. * @return Converted image. */ public static GrayS32 average( Planar<GrayS32> input , GrayS32 output ) { if (output == null) { output = new GrayS32(input.width, input.height); } else { output.reshape(input.width,input.height); } ImplConvertPlanarToGray.average(input, output); return output; }
/** * <p> * Converts an {@link boofcv.struct.image.GrayU8} 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(GrayU8 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; }
/** * <p> * Converts an {@link boofcv.struct.image.GrayS16} 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(GrayS16 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; }
public void process( final BufferedImage image ) { imageInput.reshape(image.getWidth(),image.getHeight()); imageBinary.reshape(image.getWidth(),image.getHeight()); imageOutput1.reshape(image.getWidth(),image.getHeight()); imageOutput2.reshape(image.getWidth(),image.getHeight()); imageLabeled.reshape(image.getWidth(),image.getHeight()); ConvertBufferedImage.convertFromSingle(image, imageInput, imageType); final double threshold = GThresholdImageOps.computeOtsu(imageInput,0,255); SwingUtilities.invokeLater(new Runnable() { public void run() { selectThresh.setThreshold((int) threshold); setInputImage(image); selectThresh.getHistogramPanel().update(imageInput); selectThresh.repaint(); }}); doRefreshAll(); }
/** * <p> * Converts an {@link boofcv.struct.image.GrayS8} 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(GrayS8 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; }
/** * <p> * Converts an {@link boofcv.struct.image.GrayU16} 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(GrayU16 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; }
/** * <p> * Converts an {@link boofcv.struct.image.GrayF64} 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(GrayF64 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; }
/** * Converts a {@link InterleavedS32} into a {@link GrayS32} by computing the average value of each pixel * across all the bands. * * @param input (Input) The ImageInterleaved that is being converted. Not modified. * @param output (Optional) The single band output image. If null a new image is created. Modified. * @return Converted image. */ public static GrayS32 average( InterleavedS32 input , GrayS32 output ) { if (output == null) { output = new GrayS32(input.width, input.height); } else { output.reshape(input.width,input.height); } ConvertInterleavedToSingle.average(input, output); return output; }
/** * <p> * Converts an {@link boofcv.struct.image.GrayS64} 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(GrayS64 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; }
public void process( BufferedImage input ) { setInputImage(input); this.input = input; workImage = ConvertBufferedImage.convertFromSingle(input, null, imageType); // update the binary histogram threshold for this image final double threshold = GImageStatistics.mean(workImage); binary.reshape(workImage.width,workImage.height); labeled.reshape(workImage.width,workImage.height); final int width = input.getWidth(); final int height = input.getHeight(); SwingUtilities.invokeLater(new Runnable() { public void run() { barBinary.setThreshold((int)threshold); barBinary.getHistogramPanel().update(workImage); panel.setPreferredSize(new Dimension(width,height)); processedImage = true; doRefreshAll(); }}); }
@Override public void segment(T input, GrayS32 output) { pixelToSegment.reshape(input.width, input.height); alg.process(input,pixelToSegment); ImageSegmentationOps.regionPixelId_to_Compact(pixelToSegment, alg.getRegionId(), output); }
@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; }
@Override protected void handleInputChange(int source, InputMethod method, final int width, final int height) { super.handleInputChange(source, method, width, height); binary.reshape(width,height); labeled.reshape(width,height); // reset the scaling and ensure the entire new image is visible BoofSwingUtil.invokeNowOrLater(new Runnable() { @Override public void run() { int w = guiImage.getWidth(); int h = guiImage.getHeight(); if( w == 0 ) { w = guiImage.getPreferredSize().width; h = guiImage.getPreferredSize().height; } double scale = Math.max(width/(double)w,height/(double)h); scale = Math.max(1,scale); System.out.println("scale "+scale); controls.setZoom(1.0/scale); } }); }
/** * Finds all valid ellipses in the binary image * @param binary binary image */ public void process( GrayU8 binary ) { found.reset(); labeled.reshape(binary.width, binary.height); contourFinder.process(binary, labeled); FastQueue<Contour> blobs = contourFinder.getContours(); for (int i = 0; i < blobs.size; i++) { Contour c = blobs.get(i); proccessContour(c.external); if(internalContour) { for( int j = 0; j < c.internal.size(); j++ ) { proccessContour(c.internal.get(j)); } } } }