public static Attributes writePresentation(GraphicModel model, DicomImageElement img, File outputFile, String seriesInstanceUID, String sopInstanceUID) { Attributes imgAttributes = img.getMediaReader() instanceof DcmMediaReader ? ((DcmMediaReader) img.getMediaReader()).getDicomObject() : null; return writePresentation(model, imgAttributes, outputFile, seriesInstanceUID, sopInstanceUID, null); }
private void loadArrays(DicomImageElement img, DataExplorerModel model) { // Do not load an image if another process already loading it if (preloading && !img.isLoading()) { Boolean cache = (Boolean) img.getTagValue(TagW.ImageCache); if (cache == null || !cache) { long start = System.currentTimeMillis(); try { img.getImage(); } catch (OutOfMemoryError e) { LOGGER.error("Out of memory when loading image: {}", img, e); //$NON-NLS-1$ CvUtil.runGarbageCollectorAndWait(50); return; } long stop = System.currentTimeMillis(); LOGGER.debug("Reading time: {} ms of image: {}", stop - start, img); //$NON-NLS-1$ if (model != null) { model.firePropertyChange(new ObservableEvent(ObservableEvent.BasicAction.ADD, model, null, new SeriesEvent(SeriesEvent.Action.PRELOADING, series, img))); } } } }
if (img != null && !isImageAvailable()) { int bitsStored = getBitsStored(); int bitsAllocated = getBitsAllocated(); boolean monochrome = isPhotometricInterpretationMonochrome(); if (monochrome) { Integer paddingValue = getPaddingValue(); if (paddingValue != null) { Integer paddingLimit = getPaddingLimit(); Integer paddingValueMin = (paddingLimit == null) ? paddingValue : Math.min(paddingValue, paddingLimit); Integer paddingValueMax = (paddingLimit == null) ? paddingValue : Math.max(paddingValue, paddingLimit); findMinMaxValues(img, paddingValueMin, paddingValueMax); if (!isImageAvailable()) { super.findMinMaxValues(img, !monochrome); if (bitsStored < bitsAllocated && isImageAvailable()) { boolean isSigned = isPixelRepresentationSigned(); int minInValue = isSigned ? -(1 << (bitsStored - 1)) : 0; int maxInValue = isSigned ? (1 << (bitsStored - 1)) - 1 : (1 << bitsStored) - 1; setTag(TagD.get(Tag.BitsStored), bitsAllocated); getModalityLookup(null, true);
public int getMinAllocatedValue(TagReadable tagable, boolean pixelPadding) { boolean signed = isModalityLutOutSigned(tagable, pixelPadding); int bitsAllocated = getBitsAllocated(); int maxValue = signed ? (1 << (bitsAllocated - 1)) - 1 : ((1 << bitsAllocated) - 1); return signed ? -(maxValue + 1) : 0; }
public double getFullDynamicCenter(TagReadable tagable, boolean pixelPadding) { double minValue = getMinValue(tagable, pixelPadding); double maxValue = getMaxValue(tagable, pixelPadding); return minValue + (maxValue - minValue) / 2.f; }
if (image != null && !image.isImageAvailable()) { image.getImage(); double[] val = (double[]) image.getTagValue(TagW.SlicePosition); if (val != null) { mediaEvent.setLocation(val[0] + val[1] + val[2]); Boolean cutlines = (Boolean) p.getActionValue(ActionW.SYNCH_CROSSLINE.cmd()); if (cutlines != null && cutlines) { double[] val = (double[]) image.getTagValue(TagW.SlicePosition); if (val != null) { mediaEvent.setLocation(val[0] + val[1] + val[2]); List<PresetWindowLevel> newPresetList = image.getPresetList(pixelPadding); || (windowAction.get().getSliderValue() <= 1 && levelAction.get().getSliderValue() == 0)) { if (isDefaultPresetSelected) { newPreset = image.getDefaultPreset(pixelPadding); } else { if (oldPreset != null) { newPreset = image.getDefaultPreset(pixelPadding); isDefaultPresetSelected = true; (PresentationStateReader) view2d.getActionValue(PresentationStateReader.TAG_PR_READER); if (levelMin == null || levelMax == null) { levelMin = Math.min(levelValue - windowValue / 2.0, image.getMinValue(prReader, pixelPadding)); levelMax = Math.max(levelValue + windowValue / 2.0, image.getMaxValue(prReader, pixelPadding)); } else {
? series.getMedia(MediaSeries.MEDIA_POSITION.FIRST, filter, SortSeriesStack.slicePosition) : series.getMedia(MediaSeries.MEDIA_POSITION.LAST, filter, SortSeriesStack.slicePosition); if (img != null && img.getMediaReader() instanceof DcmMediaReader) { GeometryOfSlice geometry = img.getDispSliceGeometry(); if (geometry != null) { int width = TagD.getTagValue(img, Tag.Columns, Integer.class); if (MathUtil.isDifferent(img.getRescaleX(), img.getRescaleY())) { width = img.getRescaleWidth(width); height = img.getRescaleHeight(height); confirmMessage(view, Messages.getString("SeriesBuilder.gantry"), abort); //$NON-NLS-1$ Map<TagW, Object> tags = img.getMediaReader().getMediaFragmentTags(0); if (tags != null) { double[] row = geometry.getRowArray(); final Attributes attributes = ((DcmMediaReader) img.getMediaReader()).getDicomObject(); ? SortSeriesStack.slicePosition.getReversOrderComparator() : SortSeriesStack.slicePosition); double origPixSize = img.getPixelSize(); ((DcmMediaReader) dicomSeries.getMedia(0, null, null).getMediaReader()) .writeMetaData(dicomSeries); if (study != null && treeModel != null) {
final Attributes attributes = ((DcmMediaReader) img.getMediaReader()).getDicomObject(); final int[] COPIED_ATTRS = { Tag.SpecificCharacterSet, Tag.PatientID, Tag.PatientName, Tag.PatientBirthDate, Tag.PatientBirthTime, Tag.PatientSex, Tag.IssuerOfPatientID, Tag.IssuerOfAccessionNumberSequence, rawIO.setTag(TagD.get(Tag.BitsAllocated), imgRef.getBitsAllocated()); rawIO.setTag(TagD.get(Tag.BitsStored), imgRef.getBitsStored()); double[] loc = (double[]) imgRef.getTagValue(TagW.SlicePosition); if (loc != null) { rawIO.setTag(TagW.SlicePosition, loc); Tag.StudyID, Tag.SOPClassUID, Tag.StudyDate, Tag.StudyTime, Tag.AccessionNumber); rawIO.copyTags(mtagList, img, true); rawIO.setTag(TagW.PatientPseudoUID, img.getTagValue(TagW.PatientPseudoUID)); rawIO.setTag(TagW.MonoChrome, img.getTagValue(TagW.MonoChrome));
destinationDir.mkdirs(); PlanarImage image = img.getImage(null); if (image != null && !img16) { image = img.getRenderedImage(image); ImageProcessor.writeImage(image.toMat(), destinationFile, map); if (seriesGph.contains(img.getTagValue(TagD.get(Tag.SeriesInstanceUID)))) { XmlSerializer.writePresentation(img, destinationFile); img.getFileCache().getOriginalFile().orElse(null)); img.removeImageFromCache(); } else if (node.getUserObject() instanceof MediaElement && node.getUserObject() instanceof FileExtractor) {
double[] sp = (double[]) dcm.getTagValue(TagW.SlicePosition); boolean validSp = sp != null && sp.length == 3; if (!validSp && !abort[1]) { PlanarImage image = dcm.getImage(null, false); if (image == null) { abort[0] = true; throw new IIOException("Cannot read an image!"); //$NON-NLS-1$ if (MathUtil.isDifferent(dcm.getRescaleX(), dcm.getRescaleY())) { Dimension dim = new Dimension((int) (Math.abs(dcm.getRescaleX()) * image.width()), (int) (Math.abs(dcm.getRescaleY()) * image.height())); image = ImageProcessor.scale(image.toImageCV(), dim, Imgproc.INTER_LINEAR);
int imageDataType = ImageConversion.convertToDataType(image.getImage().type()); PresetWindowLevel preset = (PresetWindowLevel) node.getParam(ActionW.PRESET.cmd()); boolean defaultPreset = LangUtil.getNULLtoTrue((Boolean) node.getParam(ActionW.DEFAULT_PRESET.cmd())); Double levelMax = (Double) node.getParam(ActionW.LEVEL_MAX.cmd()); if (levelMin == null || levelMax == null) { minLevel = Math.min(levelValue - windowValue / 2.0, image.getMinValue(prReader, pixelPadding)); maxLevel = Math.max(levelValue + windowValue / 2.0, image.getMaxValue(prReader, pixelPadding)); } else { minLevel = Math.min(levelMin, image.getMinValue(prReader, pixelPadding)); maxLevel = Math.max(levelMax, image.getMaxValue(prReader, pixelPadding)); List<PresetWindowLevel> presetList = image.getPresetList(pixelPadding); if (prReader != null) { List<PresetWindowLevel> prPresets = if (lutShapeAction.isPresent()) { Collection<LutShape> lutShapeList = imageDataType >= DataBuffer.TYPE_INT ? Arrays.asList(LutShape.LINEAR) : image.getLutShapeCollection(pixelPadding); if (prReader != null && lutShapeList != null && lutShapeItem != null && !lutShapeList.contains(lutShapeItem)) {
graphicManager.deleteByLayerType(LayerType.CROSSLINES); GraphicLayer layer = AbstractGraphicModel.getOrBuildLayer(this, LayerType.CROSSLINES); GeometryOfSlice sliceGeometry = image.getDispSliceGeometry(); if (sliceGeometry != null) { SliceOrientation sliceOrientation = this.getSliceOrientation(); addCrosshairLine(layer, pts2, color2, centerPt); PlanarImage dispImg = image.getImage(); if (dispImg != null) { Rectangle2D rect = new Rectangle2D.Double(0, 0, dispImg.width() * image.getRescaleX(), dispImg.height() * image.getRescaleY()); addRectangle(layer, rect, axial ? Color.RED : sagittal ? Color.BLUE : Color.GREEN);
double windowValue = (window == null) ? getDefaultWindow(pixPadding) : window; double levelValue = (level == null) ? getDefaultLevel(pixPadding) : level; LutShape lut = (lutShape == null) ? getDefaultShape(pixPadding) : lutShape; double minLevel; double maxLevel; if (levelMin == null || levelMax == null) { minLevel = Math.min(levelValue - windowValue / 2.0, getMinValue(prTags, pixPadding)); maxLevel = Math.max(levelValue + windowValue / 2.0, getMaxValue(prTags, pixPadding)); } else { minLevel = Math.min(levelMin, getMinValue(prTags, pixPadding)); maxLevel = Math.max(levelMax, getMaxValue(prTags, pixPadding)); LookupTableCV modalityLookup = getModalityLookup(prTags, pixPadding, invLUT); ImageCV imageModalityTransformed = modalityLookup == null ? imageSource.toImageCV() : modalityLookup.lookup(imageSource.toMat()); if ((!LangUtil.getNULLtoFalse(wlOnColorImage) || MathUtil.isEqual(windowValue, 255.0) && MathUtil.isEqual(levelValue, 127.5)) && !isPhotometricInterpretationMonochrome()) { voiLookup = getVOILookup(prTags, windowValue, levelValue, minLevel, maxLevel, lut, LangUtil.getNULLtoFalse(fillLutOutside), pixPadding);
float drawY = bound.height - border - 1.5f; // -1.5 for outline if (!image.isReadable()) { String message = Messages.getString("InfoLayer.msg_not_read"); //$NON-NLS-1$ float y = midy; String[] desc = image.getMediaReader().getReaderDescription(); if (desc != null) { for (String str : desc) { if (image.isReadable() && getDisplayPreferences(SCALE)) { drawScale(g2, bound, fontHeight); if (image.isReadable() && getDisplayPreferences(LUT) && hideMin) { drawLUT(g2, bound, midfontHeight); boolean pixelPadding = (Boolean) disOp.getParamValue(WindowOp.OP_NAME, ActionW.IMAGE_PIX_PADDING.cmd()); double minModLUT = image.getMinValue(prReader, pixelPadding); double maxModLUT = image.getMaxValue(prReader, pixelPadding); double minp = level.doubleValue() - window.doubleValue() / 2.0; double maxp = level.doubleValue() + window.doubleValue() / 2.0;
final MprView view, final Attributes attributes) throws Exception { int bitsAllocated = img.getBitsAllocated(); int bitsStored = img.getBitsStored(); double[] pixSpacing = new double[] { sPixSize, origPixSize }; Tag.StudyInstanceUID, Tag.StudyID, Tag.SOPClassUID, Tag.StudyDate, Tag.StudyTime, Tag.AccessionNumber); rawIO.copyTags(mtagList, img, true); rawIO.setTag(TagW.PatientPseudoUID, img.getTagValue(TagW.PatientPseudoUID)); rawIO.setTag(TagW.MonoChrome, img.getTagValue(TagW.MonoChrome)); double[] val = (double[]) img.getTagValue(tagList3[j]); if (val != null) { img.setTag(tagList3[j], Arrays.copyOf(val, val.length));
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); }
@Override protected boolean isGrayImage(RenderedImage source) { Boolean val = (Boolean) getTagValue(TagW.MonoChrome); return val == null ? true : val; }
Integer paddingValue = getPaddingValue(); LookupTableCV prModLut = (LookupTableCV) (tagable != null ? tagable.getTagValue(TagW.ModalityLUTData) : null); final LookupTableCV mLUTSeq = prModLut == null ? (LookupTableCV) getTagValue(TagW.ModalityLUTData) : prModLut; if (mLUTSeq != null) { if (!pixelPadding || paddingValue == null) { boolean inverseLut = isPhotometricInterpretationInverse(tagable); if (pixelPadding) { inverseLut ^= inverseLUTAction; LutParameters lutparams = getLutParameters(tagable, pixelPadding, mLUTSeq, inverseLut); if (isPhotometricInterpretationMonochrome()) { DicomImageUtils.applyPixelPaddingToModalityLUT(modalityLookup, lutparams);
PlanarImage imgPl = image.getImage(null); if (imgPl != null) { PlanarImage img = image.getRenderedImage(imgPl); thumbnail = ImageProcessor.buildThumbnail(img, new Dimension(128, 128), true); image.removeImageFromCache();
public Image(DicomImageElement image) { // Determine if the patient is prone or supine Attributes dcmItems = image.getMediaReader().getDicomObject(); this.patientPosition = dcmItems.getString(Tag.PatientPosition).toLowerCase(); this.prone = patientPosition.contains("p") ? -1 : 1; this.feetFirst = patientPosition.contains("ff") ? -1 : 1; // Get the image pixel spacing this.imageSpacing = image.getSliceGeometry().getVoxelSpacingArray(); }