public double getDefaultWindow(boolean pixelPadding) { return getMaxValue(null, pixelPadding) - getMinValue(null, pixelPadding); }
public double getDefaultLevel(boolean pixelPadding) { if (isImageAvailable()) { double min = getMinValue(null, pixelPadding); return min + (getMaxValue(null, pixelPadding) - min) / 2.0; } return 0.0f; }
@Override public void process() throws Exception { ImageElement imageElement = (ImageElement) params.get(P_IMAGE_ELEMENT); PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; Boolean auto = (Boolean) params.get(P_AUTO_LEVEL); if (auto != null && auto && imageElement != null) { double min = imageElement.getMinValue(null, true); double max = imageElement.getMaxValue(null, true); double slope = 255.0 / (max -min); double yint = 255.0 - slope * max; result = ImageProcessor.rescaleToByte(source.toImageCV(), slope, yint); } params.put(Param.OUTPUT_IMG, result); }
/** * @return return the min value after modality pixel transformation and after pixel padding operation if padding * exists. */ @Override public double getMinValue(TagReadable tagable, boolean pixelPadding) { // Computes min and max as slope can be negative return Math.min(pixel2mLUT(super.getMinValue(tagable, pixelPadding), tagable, pixelPadding), pixel2mLUT(super.getMaxValue(tagable, pixelPadding), tagable, pixelPadding)); }
/** * @return return the max value after modality pixel transformation and after pixel padding operation if padding * exists. */ @Override public double getMaxValue(TagReadable tagable, boolean pixelPadding) { // Computes min and max as slope can be negative return Math.max(pixel2mLUT(super.getMinValue(tagable, pixelPadding), tagable, pixelPadding), pixel2mLUT(super.getMaxValue(tagable, pixelPadding), tagable, pixelPadding)); }
public LutParameters getLutParameters(TagReadable tagable, boolean pixelPadding, LookupTableCV mLUTSeq, boolean inversePaddingMLUT) { Integer paddingValue = getPaddingValue(); boolean isSigned = isPixelRepresentationSigned(); int bitsStored = getBitsStored(); double intercept = getRescaleIntercept(tagable); double slope = getRescaleSlope(tagable); // No need to have a modality lookup table if (bitsStored > 16 || (MathUtil.isEqual(slope, 1.0) && MathUtil.isEqualToZero(intercept) && paddingValue == null)) { return null; } Integer paddingLimit = getPaddingLimit(); boolean outputSigned = false; int bitsOutputLut; if (mLUTSeq == null) { double minValue = super.getMinValue(tagable, pixelPadding) * slope + intercept; double maxValue = super.getMaxValue(tagable, pixelPadding) * slope + intercept; bitsOutputLut = Integer.SIZE - Integer.numberOfLeadingZeros((int) Math.round(maxValue - minValue)); outputSigned = minValue < 0 ? true : isSigned; if (outputSigned && bitsOutputLut <= 8) { // Allows to handle negative values with 8-bit image bitsOutputLut = 9; } } else { bitsOutputLut = mLUTSeq.getDataType() == DataBuffer.TYPE_BYTE ? 8 : 16; } return new LutParameters(intercept, slope, pixelPadding, paddingValue, paddingLimit, bitsStored, isSigned, outputSigned, bitsOutputLut, inversePaddingMLUT); }
if (!pixelPadding || paddingValue == null) { if (super.getMinValue(tagable, false) >= mLUTSeq.getOffset() && super.getMaxValue(tagable, false) < mLUTSeq.getOffset() + mLUTSeq.getNumEntries()) { return mLUTSeq; } else if (prModLut == null) {
private void setPreset(PresetWindowLevel preset, ImageElement img, boolean pixelPadding) { boolean p = preset != null; PRSpecialElement pr = (PRSpecialElement) getParam(P_PR_ELEMENT); setParam(ActionW.PRESET.cmd(), preset); setParam(ActionW.DEFAULT_PRESET.cmd(), true); setParam(ActionW.WINDOW.cmd(), p ? preset.getWindow() : img.getDefaultWindow(pixelPadding)); setParam(ActionW.LEVEL.cmd(), p ? preset.getLevel() : img.getDefaultLevel(pixelPadding)); setParam(ActionW.LEVEL_MIN.cmd(), img.getMinValue(pr, pixelPadding)); setParam(ActionW.LEVEL_MAX.cmd(), img.getMaxValue(pr, pixelPadding)); setParam(ActionW.LUT_SHAPE.cmd(), p ? preset.getLutShape() : img.getDefaultShape(pixelPadding)); }
@Override public void handleImageOpEvent(ImageOpEvent event) { OpEvent type = event.getEventType(); if (OpEvent.ImageChange.equals(type)) { setParam(P_IMAGE_ELEMENT, event.getImage()); } else if (OpEvent.ResetDisplay.equals(type) || OpEvent.SeriesChange.equals(type)) { ImageElement img = event.getImage(); setParam(P_IMAGE_ELEMENT, img); if (img != null) { if (!img.isImageAvailable()) { // Ensure to load image before calling the default preset that requires pixel min and max img.getImage(); } boolean pixelPadding = LangUtil.getNULLtoTrue((Boolean) getParam(ActionW.IMAGE_PIX_PADDING.cmd())); setParam(ActionW.WINDOW.cmd(), img.getDefaultWindow(pixelPadding)); setParam(ActionW.LEVEL.cmd(), img.getDefaultLevel(pixelPadding)); setParam(ActionW.LEVEL_MIN.cmd(), img.getMinValue(null, pixelPadding)); setParam(ActionW.LEVEL_MAX.cmd(), img.getMaxValue(null, pixelPadding)); } } }