public static void set(ImageSingleBand img, int x, int y, double value) { if (ImageInteger.class.isAssignableFrom(img.getClass())) { ((ImageInteger) img).set(x, y, (int) value); } else if (img instanceof ImageFloat32) { ((ImageFloat32) img).set(x, y, (float) value); } else if (img instanceof ImageFloat64) { ((ImageFloat64) img).set(x, y, value); } else { throw new IllegalArgumentException( "Unknown or incompatible image type: " + img.getClass().getSimpleName()); } }
public static BufferedImage standard(ImageSingleBand<?> src, BufferedImage dst) { if (src.getDataType().isInteger()) { ImageInteger srcInt = (ImageInteger) src; if (src.getDataType().isSigned()) { double max = GImageStatistics.maxAbs(srcInt); return colorizeSign(srcInt, dst, (int) max); } else { if (src.getDataType().getNumBits() == 8) { dst = ConvertBufferedImage.convertTo((ImageUInt8) src, dst); } else { double max = GImageStatistics.maxAbs(srcInt); dst = grayUnsigned(srcInt, dst, (int) max); } } } else if (ImageFloat32.class.isAssignableFrom(src.getClass())) { ImageFloat32 img = (ImageFloat32) src; float max = ImageStatistics.maxAbs(img); boolean hasNegative = false; for (int i = 0; i < img.getHeight(); i++) { for (int j = 0; j < img.getWidth(); j++) { if (img.get(j, i) < 0) { hasNegative = true; break; } } } if (hasNegative) return colorizeSign(img, dst, (int) max); else return grayMagnitude((ImageFloat32) src, dst, max); } return dst; }
/** * Converts an image from one type to another type. * * @param src Input image. Not modified. * @param dst Converted output image. Modified. * @return Converted image. */ @SuppressWarnings({"unchecked"}) public static void convert(ImageSingleBand<?> src, ImageSingleBand<?> dst) { if (src.getClass() == dst.getClass()) { ((ImageSingleBand) dst).setTo(src); return; } Method m = BoofTesting.findMethod(ImplConvertImage.class, "convert", src.getClass(), dst.getClass()); try { m.invoke(null, src, dst); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } }
public static double get(ImageSingleBand img, int x, int y) { if (img instanceof ImageInt8) { return ((ImageInt8) img).get(x, y); } else if (img instanceof ImageInt16) { return ((ImageInt16) img).get(x, y); } else if (img instanceof ImageSInt32) { return ((ImageSInt32) img).get(x, y); } else if (img instanceof ImageFloat32) { return ((ImageFloat32) img).get(x, y); } else if (img instanceof ImageFloat64) { return ((ImageFloat64) img).get(x, y); } else if (img instanceof ImageSInt64) { return ((ImageSInt64) img).get(x, y); } else { throw new IllegalArgumentException( "Unknown or incompatible image type: " + img.getClass().getSimpleName()); } }
/** * 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. * * @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( ImageSingleBand 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(ImageFloat32.class)) { return colorizeSign((ImageFloat32) src, dst, (float) normalize); } else { return colorizeSign((ImageInteger) src, dst, (int) normalize); } }