public static ImagePanel showWindow(ImageGray img , String title , boolean showMagnitude) { double max = GImageStatistics.maxAbs(img); BufferedImage buff; if( showMagnitude ) buff = VisualizeImageData.grayMagnitude(img,null,max); else buff = VisualizeImageData.colorizeSign(img,null,max); return showWindow(buff,title); } }
/** * <p> * Computes the variance based threshold using a modified Otsu method from an input image. Internally it uses * {@link #computeOtsu2(int[], int, int)} and {@link boofcv.alg.misc.GImageStatistics#histogram(ImageGray, double, int[])} * </p> * * @param input Input gray-scale image * @param minValue The minimum value of a pixel in the image. (inclusive) * @param maxValue The maximum value of a pixel in the image. (inclusive) * @return Selected threshold. */ public static int computeOtsu2(ImageGray input , int minValue , int maxValue ) { int range = 1+maxValue - minValue; int histogram[] = new int[ range ]; GImageStatistics.histogram(input,minValue,histogram); // Total number of pixels int total = input.width*input.height; return computeOtsu2(histogram,range,total)+minValue; }
private T ensureMaxValueOfOne(T input, double maxPixelValue) { T adjusted; if( maxPixelValue < 0 ) { maxPixelValue = GImageStatistics.max(input); } if( maxPixelValue != 1.0f ) { adjusted = this.adjusted; GPixelMath.divide(input, maxPixelValue, adjusted); } else { adjusted = input; } return adjusted; }
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(); }}); }
Planar in = (Planar) input; for (int i = 0; i < in.getNumBands(); i++) { sum += sum( in.getBand(i));
public static ImagePanel showWindow(ImageGray img , String title , boolean showMagnitude) { double max = GImageStatistics.maxAbs(img); BufferedImage buff; if( showMagnitude ) buff = VisualizeImageData.grayMagnitude(img,null,max); else buff = VisualizeImageData.colorizeSign(img,null,max); return showWindow(buff,title); } }
/** * <p> * Computes the variance based threshold using Otsu's method from an input image. Internally it uses * {@link #computeOtsu(int[], int, int)} and {@link boofcv.alg.misc.GImageStatistics#histogram(ImageGray, double, int[])} * </p> * * @param input Input gray-scale image * @param minValue The minimum value of a pixel in the image. (inclusive) * @param maxValue The maximum value of a pixel in the image. (inclusive) * @return Selected threshold. */ public static double computeOtsu(ImageGray input , double minValue , double maxValue ) { int range = (int)(1+maxValue - minValue); int histogram[] = new int[ range ]; GImageStatistics.histogram(input,minValue,histogram); // Total number of pixels int total = input.width*input.height; return computeOtsu(histogram,range,total)+minValue; }
/** * <p> * Renders a colored image where the color indicates the sign and intensity its magnitude. The input is divided * by normalize to render it in the appropriate scale. * </p> * * @param src Input single band image. * @param dst Where the image is rendered into. If null a new BufferedImage will be created and return. * @param normalize Used to normalize the input image. If ≤ 0 then the max value will be used * @return Rendered image. */ public static BufferedImage colorizeSign(ImageGray src, BufferedImage dst, double normalize) { dst = checkInputs(src, dst); if (normalize <= 0) { normalize = GImageStatistics.maxAbs(src); } if (normalize == 0) { // sets the output to black ConvertBufferedImage.convertTo(src,dst,true); return dst; } if (src.getClass().isAssignableFrom(GrayF32.class)) { return colorizeSign((GrayF32) src, dst, (float) normalize); } else { return colorizeSign((GrayI) src, dst, (int) normalize); } }
/** * <p> * Computes a threshold which maximizes the entropy between the foreground and background regions. See * {@link #computeEntropy(int[], int, int)} for more details. * </p> * * @see boofcv.alg.misc.GImageStatistics#histogram(ImageGray, double, int[]) * * @param input Input gray-scale image * @param minValue The minimum value of a pixel in the image. (inclusive) * @param maxValue The maximum value of a pixel in the image. (inclusive) * @return Selected threshold. */ public static double computeEntropy(ImageGray input , double minValue , double maxValue ) { int range = (int)(1 + maxValue - minValue); int histogram[] = new int[ range ]; GImageStatistics.histogram(input,minValue,histogram); // Total number of pixels int total = input.width*input.height; return computeEntropy(histogram, range, total)+minValue; }
/** * <p> * Renders a colored image where the color indicates the sign and intensity its magnitude. The input is divided * by normalize to render it in the appropriate scale. * </p> * * @param src Input single band image. * @param dst Where the image is rendered into. If null a new BufferedImage will be created and return. * @param normalize Used to normalize the input image. If ≤ 0 then the max value will be used * @return Rendered image. */ public static BufferedImage colorizeSign(ImageGray src, BufferedImage dst, double normalize) { dst = checkInputs(src, dst); if (normalize <= 0) { normalize = GImageStatistics.maxAbs(src); } if (normalize == 0) { // sets the output to black ConvertBufferedImage.convertTo(src,dst,true); return dst; } if (src.getClass().isAssignableFrom(GrayF32.class)) { return colorizeSign((GrayF32) src, dst, (float) normalize); } else { return colorizeSign((GrayI) src, dst, (int) normalize); } }
/** * <p> * Renders a gray scale image using color values from cold to hot. * </p> * * @param src Input single band image. * @param dst Where the image is rendered into. If null a new BufferedImage will be created and return. * @param normalize Used to normalize the input image. * @return Rendered image. */ public static BufferedImage grayMagnitudeTemp(ImageGray src, BufferedImage dst, double normalize) { if (normalize < 0) normalize = GImageStatistics.maxAbs(src); dst = checkInputs(src, dst); if (src.getDataType().isInteger()) { return grayMagnitudeTemp((GrayI) src, dst, (int) normalize); } else { throw new RuntimeException("Add support"); } }
/** * <p> * Renders a gray scale image using color values from cold to hot. * </p> * * @param src Input single band image. * @param dst Where the image is rendered into. If null a new BufferedImage will be created and return. * @param normalize Used to normalize the input image. * @return Rendered image. */ public static BufferedImage grayMagnitudeTemp(ImageGray src, BufferedImage dst, double normalize) { if (normalize < 0) normalize = GImageStatistics.maxAbs(src); dst = checkInputs(src, dst); if (src.getDataType().isInteger()) { return grayMagnitudeTemp((GrayI) src, dst, (int) normalize); } else { throw new RuntimeException("Add support"); } }
@Override public void setActiveAlgorithm(int indexFamily, String name, final Object cookie) { if( image == null ) return; D derivX = GeneralizedImageOps.createSingleBand(derivType, image.width, image.height); D derivY = GeneralizedImageOps.createSingleBand(derivType, image.width, image.height); panel.reset(); Helper h = (Helper)cookie; D derivXX = GeneralizedImageOps.createSingleBand(derivType, image.width, image.height); D derivYY = GeneralizedImageOps.createSingleBand(derivType, image.width, image.height); D derivXY = GeneralizedImageOps.createSingleBand(derivType, image.width, image.height); h.gradient.process(image,derivX,derivY); h.hessian.process(derivX,derivY,derivXX,derivYY,derivXY); double max; max = GImageStatistics.maxAbs(derivX); panel.addImage(VisualizeImageData.colorizeSign(derivX,null,max),"X-derivative"); max = GImageStatistics.maxAbs(derivY); panel.addImage(VisualizeImageData.colorizeSign(derivY,null,max),"Y-derivative"); max = GImageStatistics.maxAbs(derivXX); panel.addImage(VisualizeImageData.colorizeSign(derivXX,null,max),"XX-derivative"); max = GImageStatistics.maxAbs(derivYY); panel.addImage(VisualizeImageData.colorizeSign(derivYY,null,max),"YY-derivative"); max = GImageStatistics.maxAbs(derivXY); panel.addImage(VisualizeImageData.colorizeSign(derivXY,null,max),"XY-derivative"); processedImage = true; repaint(); }
/** * <p> * Renders a gray scale image of the input image's intensity.<br> * <br> * dst(i,j) = 255*abs(src(i,j))/normalize * </p> * * @param src Input single band image. * @param dst Where the image is rendered into. If null a new BufferedImage will be created and return. * @param normalize Used to normalize the input image. If < 0 then this value is automatically computed. * @return Rendered image. */ public static BufferedImage grayMagnitude(ImageGray src, BufferedImage dst, double normalize) { if (normalize < 0) normalize = GImageStatistics.maxAbs(src); dst = checkInputs(src, dst); if (src.getDataType().isInteger()) { return grayMagnitude((GrayI) src, dst, (int) normalize); } else if( src instanceof GrayF32){ return grayMagnitude((GrayF32) src, dst, (float) normalize); } else if( src instanceof GrayF64){ return grayMagnitude((GrayF64) src, dst, (float) normalize); } else { throw new RuntimeException("Unsupported type"); } }
/** * <p> * Renders a gray scale image of the input image's intensity.<br> * <br> * dst(i,j) = 255*abs(src(i,j))/normalize * </p> * * @param src Input single band image. * @param dst Where the image is rendered into. If null a new BufferedImage will be created and return. * @param normalize Used to normalize the input image. If < 0 then this value is automatically computed. * @return Rendered image. */ public static BufferedImage grayMagnitude(ImageGray src, BufferedImage dst, double normalize) { if (normalize < 0) normalize = GImageStatistics.maxAbs(src); dst = checkInputs(src, dst); if (src.getDataType().isInteger()) { return grayMagnitude((GrayI) src, dst, (int) normalize); } else if( src instanceof GrayF32){ return grayMagnitude((GrayF32) src, dst, (float) normalize); } else if( src instanceof GrayF64){ return grayMagnitude((GrayF64) src, dst, (float) normalize); } else { throw new RuntimeException("Unsupported type"); } }
@Override public void setActiveAlgorithm(String name, Object cookie) { DerivType type = (DerivType)cookie; panel.reset(); for( int radius = 1; radius <= 40; radius += 2 ) { int maxOrder = Math.max(type.orderX,type.orderY); double sigma = FactoryKernelGaussian.sigmaForRadius(radius,maxOrder); Class typeKer1 = FactoryKernel.getKernelType(imageType,1); Kernel1D kerX = FactoryKernelGaussian.derivativeK(typeKer1,type.orderX,sigma,radius); Kernel1D kerY = FactoryKernelGaussian.derivativeK(typeKer1,type.orderY,sigma,radius); Kernel2D kernel = GKernelMath.convolve(kerY, kerX); T smallImg = GKernelMath.convertToImage(kernel); new FDistort(smallImg,largeImg).interpNN().scaleExt().apply(); double maxValue = GImageStatistics.maxAbs(largeImg); BufferedImage out = VisualizeImageData.colorizeSign(largeImg,null,maxValue); panel.addImage(out,String.format("%5d",radius)); } }
@Override public void setActiveAlgorithm(String name, Object cookie) { DisplayGaussianKernelApp.DerivType dt = (DisplayGaussianKernelApp.DerivType)cookie; // add basis SteerableKernel<K> steerable = createKernel(dt.orderX,dt.orderY); basisPanel.reset(); for( int i = 0; i < steerable.getBasisSize(); i++ ) { T smallImg = GKernelMath.convertToImage(steerable.getBasis(i)); new FDistort(smallImg,largeImg).scaleExt().interpNN().apply(); double maxValue = GImageStatistics.maxAbs(largeImg); BufferedImage out = VisualizeImageData.colorizeSign(largeImg,null,maxValue); basisPanel.addImage(out,"Basis "+i); } // add steered kernels steerPanel.reset(); for( int i = 0; i <= 20; i++ ) { double angle = Math.PI*i/20.0; K kernel = steerable.compute(angle); T smallImg = GKernelMath.convertToImage(kernel); new FDistort(smallImg,largeImg).scaleExt().interpNN().apply(); double maxValue = GImageStatistics.maxAbs(largeImg); BufferedImage out = VisualizeImageData.colorizeSign(largeImg,null,maxValue); steerPanel.addImage(out,String.format("%5d",(int)(180.0*angle/Math.PI))); } repaint(); }