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);
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; }
@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); }