/** * Returns the maximum element value. * * @param input Input image. Not modified. * @return Maximum pixel value. */ public static int maxAbs( GrayS8 input ) { return maxAbs( input.data, input.startIndex, input.height, input.width , input.stride ); }
/** * Returns the maximum element value. * * @param input Input image. Not modified. * @return Maximum pixel value. */ public static int max( GrayS32 input ) { return max( input.data, input.startIndex, input.height, input.width , input.stride ); }
private double computeMSE(GrayF32 imageInv) { return ImageStatistics.meanDiffSq(imageInv,image); }
private double computeEdgeMSE(GrayF32 imageInv) { GrayF32 edge = new GrayF32(imageInv.width,imageInv.height); LaplacianEdge.process(image,edge); PixelMath.abs(edge,edge); float max = ImageStatistics.maxAbs(edge); PixelMath.divide(edge,max,edge); float total = ImageStatistics.sum(edge); double error = 0; for( int y = 0; y < image.height; y++ ) { for( int x = 0; x < image.width; x++ ) { double w = edge.get(x,y)/total; double e = (image.get(x,y)-imageInv.get(x,y)); error += (e*e)*w; } } return error; }
/** * Returns the mean pixel intensity value. * * @param img Input image. Not modified. * @return Mean pixel intensity value */ public static float mean( GrayF32 img ) { return sum(img)/(float)(img.width*img.height); }
@Override public void setInputImage(GrayF32 image) { enlargedTemplate.reshape(image.width,image.height); fftImage.reshape(image.width,image.height); fftTemplate.reshape(image.width,image.height); fftMult.reshape(image.width,image.height); correlation.reshape(image.width,image.height); normalizedImage.reshape(image.width,image.height); maxValue = ImageStatistics.max(image)+0.0001f;// avoid divide by zero errors mean = ImageStatistics.mean(image); PixelMath.divide(image,maxValue,normalizedImage); PixelMath.minus(normalizedImage,mean/maxValue,normalizedImage); dft.forward(normalizedImage, fftImage); }
/** * Computes the histogram of intensity values for the image. For floating point images it is rounded * to the nearest integer using "(int)value". * * @param input (input) Image. * @param minValue (input) Minimum possible intensity value Ignored for unsigned images. * @param histogram (output) Storage for histogram. Number of elements must be equal to max value. */ public static void histogram(ImageGray input , double minValue , int histogram[] ) { if( GrayU8.class == input.getClass() ) { ImageStatistics.histogram((GrayU8)input,(int)minValue,histogram); } else if( GrayS8.class == input.getClass() ) { ImageStatistics.histogram((GrayS8)input,(int)minValue,histogram); } else if( GrayU16.class == input.getClass() ) { ImageStatistics.histogram((GrayU16)input,(int)minValue,histogram); } else if( GrayS16.class == input.getClass() ) { ImageStatistics.histogram((GrayS16)input,(int)minValue,histogram); } else if( GrayS32.class == input.getClass() ) { ImageStatistics.histogram((GrayS32)input,(int)minValue,histogram); } else if( GrayS64.class == input.getClass() ) { ImageStatistics.histogram((GrayS64)input,(long)minValue,histogram); } else if( GrayF32.class == input.getClass() ) { ImageStatistics.histogram((GrayF32)input,(float)minValue,histogram); } else if( GrayF64.class == input.getClass() ) { ImageStatistics.histogram((GrayF64)input,minValue,histogram); } else { throw new IllegalArgumentException("Unknown image Type"); } } }
return ImageStatistics.mean((GrayU8) input); } else if (GrayS8.class == input.getClass()) { return ImageStatistics.mean((GrayS8) input); } else if (GrayU16.class == input.getClass()) { return ImageStatistics.mean((GrayU16) input); } else if (GrayS16.class == input.getClass()) { return ImageStatistics.mean((GrayS16) input); } else if (GrayS32.class == input.getClass()) { return ImageStatistics.mean((GrayS32) input); } else if (GrayS64.class == input.getClass()) { return ImageStatistics.mean((GrayS64) input); } else if (GrayF32.class == input.getClass()) { return ImageStatistics.mean((GrayF32) input); } else if (GrayF64.class == input.getClass()) { return ImageStatistics.mean((GrayF64) input); } else { throw new IllegalArgumentException("Unknown image Type"); return ImageStatistics.mean((InterleavedU8) input); } else if (InterleavedS8.class == input.getClass()) { return ImageStatistics.mean((InterleavedS8) input); } else if (InterleavedU16.class == input.getClass()) { return ImageStatistics.mean((InterleavedU16) input); } else if (InterleavedS16.class == input.getClass()) { return ImageStatistics.mean((InterleavedS16) input); } else if (InterleavedS32.class == input.getClass()) { return ImageStatistics.mean((InterleavedS32) input); } else if (InterleavedS64.class == input.getClass()) { return ImageStatistics.mean((InterleavedS64) input);
/** * Returns the mean pixel intensity value. * * @param img Input image. Not modified. * @return Mean pixel intensity value */ public static double mean( InterleavedF64 img ) { return sum(img)/(double)(img.width*img.height*img.numBands); }
@Override public void process(GrayU8 input) { ImageStatistics.histogram(input,0, histogram); EnhanceImageOps.equalize(histogram, transform); EnhanceImageOps.applyTransform(input, transform, enhanced); renderOutput(enhanced); } }
public BufferedImage findRoad(BufferedImage src) { // convert into a usable format ImageFloat32 input = ConvertBufferedImage.convertFromSingle(src, null, ImageFloat32.class); ImageUInt8 binary = new ImageUInt8(input.width, input.height); ImageSInt32 blobs = new ImageSInt32(input.width, input.height); // the mean pixel value is often a reasonable threshold when creating a binary image double mean = ImageStatistics.mean(input); // create a binary image ThresholdImageOps.threshold(input, binary, (float) mean, true); // remove small blobs through erosion and dilation // The null in the input indicates that it should internally declare the work image it needs // this is less efficient, but easier to code. for (int i = 0; i < 1; i++) { binary = BinaryImageOps.erode8(binary,1, null); } for (int i = 0; i < 2; i++) { binary = BinaryImageOps.dilate8(binary,1, null); } // Detect blobs inside the binary image and assign labels to them List<Contour> blobContours = BinaryImageOps.contour(binary, ConnectRule.FOUR, blobs); int numBlobs = filterBlobsNotTouchingEdges(blobs, blobContours.size()); // Render the binary image for output and display it in a window BufferedImage dst = VisualizeBinaryData.renderLabeled(blobs, numBlobs, null); return dst; }
/** * Returns the maximum element value. * * @param input Input image. Not modified. * @return Maximum pixel value. */ public static int maxAbs( InterleavedS16 input ) { return maxAbs( input.data, input.startIndex, input.height, input.width*input.numBands , input.stride ); }
/** * Returns the maximum element value. * * @param input Input image. Not modified. * @return Maximum pixel value. */ public static float max( InterleavedF32 input ) { return max( input.data, input.startIndex, input.height, input.width*input.numBands , input.stride ); }
/** * Returns the mean pixel intensity value. * * @param img Input image. Not modified. * @return Mean pixel intensity value */ public static double mean( GrayS8 img ) { return sum(img)/(double)(img.width*img.height); }
/** * <p>Computes the mean squared error (MSE) between the two images.</p> * * @param imgA first image. Not modified. * @param imgB second image. Not modified. * @return error between the two images. */ public static double meanDiffSq(InterleavedS8 imgA, InterleavedS8 imgB ) { InputSanityCheck.checkSameShape(imgA,imgB); return meanDiffSq(imgA.data,imgA.startIndex,imgA.stride, imgB.data,imgB.startIndex,imgB.stride, imgA.height, imgA.width*imgA.numBands); }
@Override public void process(Planar<GrayU8> input) { ConvertImage.average(input,gray); ImageStatistics.histogram(gray,0, histogram); EnhanceImageOps.equalize(histogram, transform); for( int i = 0; i < 3; i++ ) EnhanceImageOps.applyTransform(input.getBand(i), transform, enhanced.getBand(i)); renderOutput(enhanced); } }
/** * Returns the maximum element value. * * @param input Input image. Not modified. * @return Maximum pixel value. */ public static long maxAbs( InterleavedS64 input ) { return maxAbs( input.data, input.startIndex, input.height, input.width*input.numBands , input.stride ); }
/** * Returns the maximum element value. * * @param input Input image. Not modified. * @return Maximum pixel value. */ public static int max( InterleavedS32 input ) { return max( input.data, input.startIndex, input.height, input.width*input.numBands , input.stride ); }
/** * Returns the mean pixel intensity value. * * @param img Input image. Not modified. * @return Mean pixel intensity value */ public static double mean( InterleavedS8 img ) { return sum(img)/(double)(img.width*img.height*img.numBands); }
/** * <p>Computes the mean squared error (MSE) between the two images.</p> * * @param imgA first image. Not modified. * @param imgB second image. Not modified. * @return error between the two images. */ public static double meanDiffSq(GrayS64 imgA, GrayS64 imgB ) { InputSanityCheck.checkSameShape(imgA,imgB); return meanDiffSq(imgA.data,imgA.startIndex,imgA.stride, imgB.data,imgB.startIndex,imgB.stride, imgA.height, imgA.width); }