/** * Get the logged image value. * * @param bean * @return a dataset that can be absolute, if complex, and also be logged according to bean * Package private for testing */ /* package */ Dataset getImageLoggedDataCalc(ImageServiceBean bean) { Dataset ret = DatasetUtils.convertToDataset(bean.getImage()); if (ret.isComplex()) { ret = Maths.abs(ret); } if (bean.isLogColorScale()) { double offset = bean.getLogOffset(); if (!Double.isNaN(offset) && !Double.isInfinite(offset)) { ret = Maths.subtract(ret, offset); } ret = Maths.log10(ret); } return ret; }
/** * getImageData(...) provides an image in a given palette data and origin. Faster than getting a * resolved image * * <p>This method should be thread safe. */ public ImageData getImageData(ImageServiceBean bean) { ImageOrigin origin = bean.getOrigin(); if (origin == null) origin = ImageOrigin.TOP_LEFT; // orientate the image Dataset oImage = DatasetUtils.rotate90(DatasetUtils.convertToDataset(bean.getImage()), origin.ordinal()); Dataset image = oImage; if (image instanceof RGBDataset) { return SWTImageUtils.createImageData( (RGBDataset) image, 0, 255, null, null, null, false, false, false); } createMaxMin(bean); double max = getMax(bean); double min = getMin(bean); double maxCut = getMaxCut(bean); double minCut = getMinCut(bean); // now deal with the log if needed if (bean.isLogColorScale()) { image = DatasetUtils.rotate90(getImageLoggedData(bean), origin.ordinal()); max = Math.log10(max); // note createMaxMin() -> getFastStatistics() -> getImageLogged() which ensures min >= 0 min = Math.log10(min); maxCut = Math.log10(maxCut); // no guarantees for minCut though minCut = minCut <= 0 ? Double.NEGATIVE_INFINITY : Math.log10(minCut); } if (oImage.isComplex()) { // handle complex datasets by creating RGB dataset Dataset hue = Maths.angle(oImage, true); Dataset value = DatasetUtils.rotate90(getImageLoggedData(bean), origin.ordinal()); double maxmax = Math.max(Math.abs(max), Math.abs(min)); if (max - min > Math.ulp(maxmax)) { value.isubtract(min); value.imultiply(1. / (max - min)); } else { value.imultiply(1. / maxmax); } image = RGBDataset.createFromHSV(hue, null, value); return SWTImageUtils.createImageData(image, 0, 255, null, null, null, false, false, false); } if (bean.getFunctionObject() != null && bean.getFunctionObject() instanceof FunctionContainer) { final FunctionContainer fc = (FunctionContainer) bean.getFunctionObject(); // TODO This does not support masking or cut bounds for zingers and dead pixels. return SWTImageUtils.createImageData( image, min, max, fc.getRedFunc(), fc.getGreenFunc(), fc.getBlueFunc(), fc.isInverseRed(), fc.isInverseGreen(), fc.isInverseBlue()); } return SWTImageUtils.createImageData(min, max, minCut, maxCut, image, bean); }