public void Transform(DcmDataset dataset) { if (dataset.Contains(_src)) { dataset.AddElementWithValueString(_dst, dataset.GetValueString(_src)); } }
public void Transform(DcmDataset dataset) { if (dataset.Contains(_tag) && dataset.GetValueString(_tag) == _match) { dataset.AddElementWithValueString(_tag, _value); } }
public void Transform(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); dataset.AddElementWithValueString(_tag, value.ToLower()); } }
public void Transform(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); dataset.AddElementWithValueString(_tag, _prefix + value); } }
public bool Match(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag).Trim(); return(String.IsNullOrEmpty(value)); } return(true); }
public bool Match(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); return(value.EndsWith(_value)); } return(false); }
public bool Match(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); return(Wildcard.Match(_pattern, value)); } return(false); }
public bool Match(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); return(_regex.IsMatch(value)); } return(false); }
public void Transform(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); value = Regex.Replace(value, _pattern, _replacement); dataset.AddElementWithValueString(_tag, value); } }
public void Transform(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); string[] parts = value.Split(_seperators); value = String.Format(_format, parts); dataset.AddElementWithValueString(_tag, value); } }
public static WindowLevel[] FromDataset(DcmDataset dataset) { List <WindowLevel> settings = new List <WindowLevel>(); if (dataset.Contains(DicomTags.WindowCenter) && dataset.Contains(DicomTags.WindowWidth)) { string[] wc = dataset.GetDS(DicomTags.WindowCenter).GetValues(); string[] ww = dataset.GetDS(DicomTags.WindowWidth).GetValues(); if (wc.Length != ww.Length) { throw new DicomImagingException("Window Center count does not match Window Width count"); } string[] desc = null; if (dataset.Contains(DicomTags.WindowCenterWidthExplanation)) { desc = dataset.GetLO(DicomTags.WindowCenterWidthExplanation).GetValues(); } for (int i = 0; i < wc.Length; i++) { double window; double level; if (!Double.TryParse(ww[i], out window) || !Double.TryParse(wc[i], out level)) { throw new DicomImagingException("Unable to parse Window/Level [wc: {0}; ww: {1}]", wc[i], ww[i]); } string description = String.Empty; if (desc != null && i < desc.Length) { description = desc[i]; } settings.Add(new WindowLevel(description, window, level)); } } return(settings.ToArray()); }
private void Load(DcmDataset ds) { _rows = ds.GetUInt16(OverlayTag(DicomTags.OverlayRows), 0); _columns = ds.GetUInt16(OverlayTag(DicomTags.OverlayColumns), 0); _type = ds.GetString(OverlayTag(DicomTags.OverlayType), "Unknown"); DicomTag tag = OverlayTag(DicomTags.OverlayOrigin); if (ds.Contains(tag)) { short[] xy = ds.GetSS(tag).GetValues(); if (xy != null && xy.Length == 2) { _originX = xy[0]; _originY = xy[1]; } } _bitsAllocated = ds.GetUInt16(OverlayTag(DicomTags.OverlayBitsAllocated), 1); _bitPosition = ds.GetUInt16(OverlayTag(DicomTags.OverlayBitPosition), 0); tag = OverlayTag(DicomTags.OverlayData); if (ds.Contains(tag)) { DcmElement elem = ds.GetElement(tag); _data = elem.ByteBuffer.ToBytes(); } _description = ds.GetString(OverlayTag(DicomTags.OverlayDescription), String.Empty); _subtype = ds.GetString(OverlayTag(DicomTags.OverlaySubtype), String.Empty); _label = ds.GetString(OverlayTag(DicomTags.OverlayLabel), String.Empty); _frames = ds.GetInt32(OverlayTag(DicomTags.NumberOfFramesInOverlay), 1); _frameOrigin = ds.GetUInt16(OverlayTag(DicomTags.ImageFrameOrigin), 1); //TODO: include ROI }
public bool Match(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); foreach (string v in _values) { if (v == value) { return(true); } } } return(false); }
public void Transform(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); if (_totalLength < 0) { value = value.PadLeft(-_totalLength, _paddingChar); } else { value = value.PadRight(_totalLength, _paddingChar); } dataset.AddElementWithValueString(_tag, value); } }
public void Transform(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); string[] parts = value.Split('\\'); for (int i = 0; i < parts.Length; i++) { if (parts[i].Length > _length) { parts[i] = parts[i].Substring(0, _length); } } value = String.Join("\\", parts); dataset.AddElementWithValueString(_tag, value); } }
private void DumpDisplayDataset(string instanceName, DcmDataset dataset) { if (dataset != null) { var xmlDoc = XDicom.ToXML(dataset, XDicomOptions.None); var txtWriter = new StringWriter(); xmlDoc.Save(txtWriter); dicomDumpTextBox.Text = txtWriter.ToString(); dicomImage.Source = dataset.Contains(DicomTags.PixelData) ? GetImageSource(dataset) : null; } else { dicomDumpTextBox.Text = String.Format(Resources["noDicomDataMsg"].ToString(), instanceName); dicomImage.Source = null; } }
public void Transform(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); if (_position == DicomTrimPosition.Both) { if (_trim != null) { value = value.Trim(_trim); } else { value = value.Trim(); } } else if (_position == DicomTrimPosition.Start) { if (_trim != null) { value = value.TrimStart(_trim); } else { value = value.TrimStart(); } } else { if (_trim != null) { value = value.TrimEnd(_trim); } else { value = value.TrimEnd(); } } dataset.AddElementWithValueString(_tag, value); } }
public override void FromDataset(DcmDataset dataset) { //dataset.Dump(); _dataset = dataset; dataset.LoadDicomFields(this); if (dataset.Contains(DicomTags.ScheduledProcedureStepSequence)) { DcmItemSequence sq = dataset.GetSQ(DicomTags.ScheduledProcedureStepSequence); if (sq.SequenceItems.Count > 0) { DcmItemSequenceItem sps = sq.SequenceItems[0]; Modality = sps.Dataset.GetString(DicomTags.Modality, String.Empty); ScheduledStationAETitle = sps.Dataset.GetString(DicomTags.ScheduledStationAETitle, String.Empty); ScheduledProcedureStartDate = sps.Dataset.GetDateTime(DicomTags.ScheduledProcedureStepStartDate, 0, DateTime.MinValue); ScheduledProcedureStartTime = sps.Dataset.GetDateTime(DicomTags.ScheduledProcedureStepStartTime, 0, DateTime.MinValue); ScheduledPerformingPhysicianName = sps.Dataset.GetString(DicomTags.ScheduledPerformingPhysiciansName, String.Empty); ScheduledProcedureStepDescription = sps.Dataset.GetString(DicomTags.ScheduledProcedureStepDescription, String.Empty); ScheduledProcedureStepID = sps.Dataset.GetString(DicomTags.ScheduledProcedureStepID, String.Empty); ScheduledProcedureStepLocation = sps.Dataset.GetString(DicomTags.ScheduledProcedureStepLocation, String.Empty); } } }
public void Transform(DcmDataset dataset) { if (dataset.Contains(_tag)) { string value = dataset.GetValueString(_tag); if (_position == DicomTrimPosition.Start || _position == DicomTrimPosition.Both) { while (value.StartsWith(_trim)) { value = value.Substring(_trim.Length); } } if (_position == DicomTrimPosition.End || _position == DicomTrimPosition.Both) { while (value.EndsWith(_trim)) { value = value.Substring(0, value.Length - _trim.Length); } } dataset.AddElementWithValueString(_tag, value); } }
public DcmPixelData(DcmDataset dataset) { _transferSyntax = dataset.InternalTransferSyntax; _lossy = dataset.GetString(DicomTags.LossyImageCompression, "00") != "00"; _lossyMethod = dataset.GetString(DicomTags.LossyImageCompressionMethod, String.Empty); _lossyRatio = dataset.GetString(DicomTags.LossyImageCompressionRatio, String.Empty); _frames = dataset.GetInt32(DicomTags.NumberOfFrames, 1); _width = dataset.GetUInt16(DicomTags.Columns, 0); _height = dataset.GetUInt16(DicomTags.Rows, 0); _bitsStored = dataset.GetUInt16(DicomTags.BitsStored, 0); _bitsAllocated = dataset.GetUInt16(DicomTags.BitsAllocated, 0); _highBit = dataset.GetUInt16(DicomTags.HighBit, (ushort)(_bitsStored - 1)); _samplesPerPixel = dataset.GetUInt16(DicomTags.SamplesPerPixel, 0); _pixelRepresentation = dataset.GetUInt16(DicomTags.PixelRepresentation, 0); _planarConfiguration = dataset.GetUInt16(DicomTags.PlanarConfiguration, 0); _photometricInterpretation = dataset.GetString(DicomTags.PhotometricInterpretation, String.Empty); _rescaleSlope = dataset.GetDouble(DicomTags.RescaleSlope, 1.0); _rescaleIntercept = dataset.GetDouble(DicomTags.RescaleIntercept, 0.0); _pixelDataItem = dataset.GetItem(DicomTags.PixelData); _hasPixelPadding = dataset.Contains(DicomTags.PixelPaddingValue); if (_hasPixelPadding) { DcmElement elem = dataset.GetElement(DicomTags.PixelPaddingValue); if (elem is DcmUnsignedShort && elem.GetVM() > 0) { _pixelPaddingValue = (elem as DcmUnsignedShort).GetValue(); } else if (elem is DcmSignedShort && elem.GetVM() > 0) { _pixelPaddingValue = (elem as DcmSignedShort).GetValue(); } else { _pixelPaddingValue = MinimumDataValue; } } }
private DicomReadStatus ParseTag(DicomTag stopAtTag, DicomReadOptions options) { if (_tag == null) { if (_remain >= 4) { _pos = _stream.Position + _offset; ushort g = _reader.ReadUInt16(); if (Flags.IsSet(options, DicomReadOptions.FileMetaInfoOnly) && g != 0x0002) { _stream.Seek(-2, SeekOrigin.Current); return(DicomReadStatus.SuccessEndRead); } ushort e = _reader.ReadUInt16(); if (DicomTag.IsPrivateGroup(g) && e > 0x00ff) { uint card = DicomTag.GetCard(g, e); if ((card & 0xffffff00) != _privateCreatorCard) { _privateCreatorCard = card & 0xffffff00; DicomTag pct = DicomTag.GetPrivateCreatorTag(g, e); DcmDataset ds = _dataset; if (_sds.Count > 0 && _sds.Count == _sqs.Count) { ds = _sds.Peek(); if (!ds.Contains(pct)) { ds = _dataset; } } _privateCreatorId = ds.GetString(pct, String.Empty); } _tag = new DicomTag(g, e, _privateCreatorId); } else { _tag = new DicomTag(g, e); if (g == 0xfffe) { if (_tag == DicomTags.Item || _tag == DicomTags.ItemDelimitationItem || _tag == DicomTags.SequenceDelimitationItem) { _vr = DicomVR.NONE; } } } _remain -= 4; _bytes += 4; _read += 4; } else { return(NeedMoreData(4)); } } if (_tag == DicomTags.ItemDelimitationItem && Flags.IsSet(options, DicomReadOptions.SequenceItemOnly)) { return(DicomReadStatus.SuccessEndRead); } if (_tag >= stopAtTag) { return(DicomReadStatus.SuccessEndRead); } return(DicomReadStatus.Success); }
public bool Match(DcmDataset dataset) { return(dataset.Contains(_tag)); }
private void DrawImageBox(DcmImageBox imageBox, Graphics graphics, Point position, int width, int height, int dpiX, int dpiY) { DcmDataset dataset = imageBox.ImageSequence; if (!dataset.Contains(DicomTags.PixelData)) { return; } DcmPixelData pixelData = new DcmPixelData(dataset); PinnedIntArray pixelBuffer = null; Bitmap bitmap = null; if (pixelData.SamplesPerPixel == 3) { pixelBuffer = new PinnedIntArray(pixelData.GetFrameDataS32(0)); bitmap = new Bitmap(pixelData.ImageWidth, pixelData.ImageHeight, pixelData.ImageWidth * sizeof(int), PixelFormat.Format32bppRgb, pixelBuffer.Pointer); } else { bool invert = (pixelData.PhotometricInterpretation == "MONOCHROME1"); if (imageBox.Polarity == "REVERSE") { invert = !invert; } byte[] pixelsOut = null; if (pixelData.BitsAllocated == 8) { pixelsOut = pixelData.GetFrameDataU8(0); } else { ushort[] pixels = pixelData.GetFrameDataU16(0); pixelsOut = new byte[pixels.Length]; double scale = 256.0 / 4096.0; int pixel = 0; for (int y = 0; y < pixelData.ImageHeight; y++) { for (int x = 0; x < pixelData.ImageWidth; x++) { pixelsOut[pixel] = (byte)(pixels[pixel] * scale); pixel++; } } pixels = null; } bitmap = new Bitmap(pixelData.ImageWidth, pixelData.ImageHeight, PixelFormat.Format8bppIndexed); if (invert) { ColorTable.Apply(bitmap, ColorTable.Monochrome1); } else { ColorTable.Apply(bitmap, ColorTable.Monochrome2); } BitmapData bmData = bitmap.LockBits(new Rectangle(0, 0, pixelData.ImageWidth, pixelData.ImageHeight), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); IntPtr pos = bmData.Scan0; for (int i = 0, c = pixelsOut.Length; i < c; i += bmData.Width) { Marshal.Copy(pixelsOut, i, pos, bmData.Width); pos = new IntPtr(pos.ToInt64() + bmData.Stride); } bitmap.UnlockBits(bmData); } //bitmap.SetResolution(dpiX, dpiY); int border = 3; double factor = Math.Min((double)height / (double)bitmap.Height, (double)width / (double)bitmap.Width); int drawWidth = (int)(bitmap.Width * factor) - (border * 2); int drawHeight = (int)(bitmap.Height * factor) - (border * 2); int drawX = position.X + ((width - drawWidth) / 2); int drawY = position.Y + ((height - drawHeight) / 2); graphics.DrawImage(bitmap, drawX, drawY, drawWidth, drawHeight); }