/// <summary> /// Renders DICOM image to <see cref="System.Windows.Media.ImageSource"/> /// </summary> /// <param name="frame">Zero indexed frame nu,ber</param> /// <returns>Rendered image</returns> public ImageSource RenderImageSource(int frame = 0) { if (frame != _currentFrame || _pixelData == null) Load(Dataset, frame); ImageGraphic graphic = new ImageGraphic(_pixelData); foreach (var overlay in _overlays) { // DICOM overlay origin begins at (1,1) OverlayGraphic og = new OverlayGraphic(PixelDataFactory.Create(overlay), overlay.OriginX - 1, overlay.OriginY - 1, OverlayColor); graphic.AddOverlay(og); } return graphic.RenderImageSource(_pipeline.LUT); }
/// <summary> /// Renders DICOM image to <see cref="System.Windows.Media.ImageSource"/> /// </summary> /// <param name="frame">Zero indexed frame nu,ber</param> /// <returns>Rendered image</returns> public ImageSource RenderImageSource(int frame = 0) { if (frame != _currentFrame || _pixelData == null) Load(Dataset, frame); var graphic = new ImageGraphic(_pixelData); if (ShowOverlays) { foreach (var overlay in _overlays) { if ((frame + 1) < overlay.OriginFrame || (frame + 1) > (overlay.OriginFrame + overlay.NumberOfFrames - 1)) continue; var og = new OverlayGraphic(PixelDataFactory.Create(overlay), overlay.OriginX - 1, overlay.OriginY - 1, OverlayColor); graphic.AddOverlay(og); } } return graphic.RenderImageSource(_pipeline.LUT); }
return graphic.RenderImageSource(_pipeline.LUT); } private void Load(DcmDataset dataset) { Dataset = dataset; if (Dataset.InternalTransferSyntax.IsEncapsulated) Dataset.ChangeTransferSyntax(DicomTransferSyntax.ExplicitVRLittleEndian, null); DcmPixelData pixelData = new DcmPixelData(Dataset); _pixelData = PixelDataFactory.Create(pixelData, 0); _pipeline = PipelineFactory.Create(Dataset, pixelData); pixelData.Unload(); _overlays = DcmOverlayData.FromDataset(Dataset);
/// <summary>Renders DICOM image to System.Drawing.Image</summary> /// <param name="frame">Zero indexed frame number</param> /// <returns>Rendered image</returns> public Image RenderImage(int frame = 0) { if (frame != _currentFrame || _pixelData == null) Load(Dataset, frame); var graphic = new ImageGraphic(_pixelData); try { if (ShowOverlays) { foreach (var overlay in _overlays) { if ((frame + 1) < overlay.OriginFrame || (frame + 1) > (overlay.OriginFrame + overlay.NumberOfFrames - 1)) continue; var og = new OverlayGraphic(PixelDataFactory.Create(overlay), overlay.OriginX - 1, overlay.OriginY - 1, OverlayColor); graphic.AddOverlay(og); og.Scale(this._scale); } } var image = graphic.RenderImage(_pipeline.LUT); return new Bitmap(image); } finally { if (graphic != null) { graphic.Dispose(); } } }
/// <summary>Renders DICOM image to System.Drawing.Image</summary> /// <returns>Rendered image</returns> public Image Render() { ImageGraphic graphic = new ImageGraphic(_pixelData); return graphic.RenderImage(_pipeline.LUT); }