6000 Tag / Overlay Question

610 views
Skip to first unread message

Chris Horn

unread,
Jul 18, 2013, 10:14:19 PM7/18/13
to fo-d...@googlegroups.com
Hi Colby and all,

I have need to create DICOM overlay, is there anything in the fo-toolkit to do this already ?
or would I be able to take a bitmap - convert it to a 1 bit image and constuct a 6000 tag sequence then add it to the dataset?

any thoughts or suggestions?

Vladimir Tregub

unread,
Jul 22, 2013, 2:16:42 AM7/22/13
to fo-d...@googlegroups.com
You seem like requesting an example of Dicom.Imaging.Render namespace usage, but
maybe you will be happy with this:
 
 
 
using System;
using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Dicom;
using Dicom.IO;
using Dicom.IO.Buffer;
namespace OverlayFromTextBlock
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                DicomFile df = DicomFile.Open("smpte.dcm");
                ushort width = df.Dataset.Get<ushort>(DicomTag.Columns);
                ushort height = df.Dataset.Get<ushort>(DicomTag.Rows);
                var grid = new Grid { Width = width, Height = height };
                var text = new TextBlock
                       {
                         Text = "OVERLAY",
                         FontSize = 32,
                         FontWeight = FontWeights.Bold, 
                         HorizontalAlignment = HorizontalAlignment.Center
                       };
                grid.Children.Add(text);
                grid.Measure(new Size(grid.Width, grid.Height));
                grid.Arrange(new Rect(new Size(grid.Width, grid.Height)));
                var rtb = new RenderTargetBitmap(
                                    (int)grid.Width,
                                    (int)grid.Height,
                                    96,
                                    96,
                                    PixelFormats.Pbgra32);
                rtb.Render(grid);
                int stride = rtb.PixelWidth * 4;
                int size = rtb.PixelHeight * stride;
                byte[] coloredPixels = new byte[size];
                rtb.CopyPixels(coloredPixels, stride, 0);
                byte[] pixels = new byte[size/4];
  
                df.Dataset.Add(new DicomUnsignedShort(new DicomTag(0x6000,0x0010), width));
                df.Dataset.Add(new DicomUnsignedShort(new DicomTag(0x6000,0x0011), height)); 
                df.Dataset.Add(new DicomCodeString(new DicomTag(0x6000,0x0040), "G"));
                df.Dataset.Add(new DicomSignedShort(new DicomTag(0x6000,0x0050), new short[] {1, 1}));
                df.Dataset.Add(new DicomUnsignedShort(new DicomTag(0x6000,0x0100), 1));
                df.Dataset.Add(new DicomUnsignedShort(new DicomTag(0x6000,0x0102), 0));
                BitArray bits = new BitArray(width * height);
                for (int i = 0; i < size/4; i++)
                {
                    bits[i] = coloredPixels[4*i+3]==0 ? false : true;
                }
                byte[] packedbitarray = new byte[Math.Max(1, bits.Length / 8)];
                bits.CopyTo(packedbitarray, 0);
                MemoryByteBuffer buffer = new MemoryByteBuffer(packedbitarray);
                df.Dataset.Add(new DicomOtherByte(new DicomTag(0x6000,0x3000), buffer));
                DicomFile dfnew = new DicomFile(df.Dataset);
                dfnew.Save("overlay.dcm");
             }
             catch (Exception e) { Console.WriteLine(e.Message); }
        }
    }
}

Chris Horn

unread,
Jul 22, 2013, 5:58:01 PM7/22/13
to fo-d...@googlegroups.com
Hi Vladimir,

Thanks for the reply, I was after conformation of the way I looking to move forward, and you've given me that, I'm looking to convert measurements, ROI's, cob angle's etc to overlays
when exporting for our pacs.

Thanks again, btw should put that on a gist as that could be useful for others

Colby Dillion

unread,
Feb 6, 2014, 1:35:26 PM2/6/14
to fo-d...@googlegroups.com
Take a look at DicomOverlayData.FromBitmap() in the Dicom.Imaging namespace.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages