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; }
public static BufferedImage graySign(ImageFloat32 src, BufferedImage dst, float maxAbsValue) { dst = checkInputs(src, dst); if (maxAbsValue < 0) maxAbsValue = ImageStatistics.maxAbs(src); for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { float v = src.get(x, y); int rgb = 127 + (int) (127 * v / maxAbsValue); dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb); } } return dst; }