extracting Z from MultiFrame Dicom Image

1,011 views
Skip to first unread message

Matias

unread,
Sep 2, 2014, 3:10:54 PM9/2/14
to fo-d...@googlegroups.com
Hi,

I have an image which consist in multiframe and I would like to extract the Z of each slice, is that possible with Fo-Dicom?

I currently extract the Z of individual images by doing this:

Z = img.Dataset.Get<decimal>(Dicom.DicomTag.ImagePositionPatient, 2);

but with multiframe images, I'm stuck..

Thanks,

Matias.

Chris Horn

unread,
Sep 2, 2014, 11:45:27 PM9/2/14
to fo-d...@googlegroups.com
are you just trying to render a given frame or extract frame x as an individual Dicom image?

here are 2 methods you can use
1.  use render method
private void GenerateFrameList()
        {
            _framesList = new List<ImageSource>();
 
            var numberofFrames = CurrenBinder.Dataset.Get<Int32>(DicomTag.NumberOfFrames);
            for (var i = 0i < numberofFramesi++)
            {
                var imgSource = new DicomImage(CurrenBinder.Dataset).RenderImageSource(i);
                imgSource.Freeze();
                _framesList.Add(imgSource);
            }
        }


2.Customer function to return a given frame as a DICOM image *****NOTE*******, this will not always pass validation rules
public static MemoryStream ExtractImageFromMultiframe(String virtualFileName)
{
     var _logger = LogManager.GetCurrentClassLogger();
     _logger.Trace(String.Format("ExtractImageFromMultiframe"));
 
    if (!virtualFileName.ToUpper().Contains("-FRAME"))
        throw new ArgumentOutOfRangeException("virtualFileName""virtualFileName must specify the frame to extract from source multiframe");
 
    // decipher key information from supplied virtual filename
    var fileNameOnly = Path.GetFileNameWithoutExtension(virtualFileName);
    var fileExtension = Path.GetExtension(virtualFileName);
    var seriesPath = Path.GetDirectoryName(virtualFileName);
 
    var frameNumberString = fileNameOnly.Substring(fileNameOnly.Length - 4);
    var frameNumber = Convert.ToInt32(frameNumberString);
 
    // determine the source file's name
    var multiframeFile = fileNameOnly.Substring(0fileNameOnly.IndexOf("-")) + fileExtension;
    var multiFrameFullPath = Path.Combine(seriesPathmultiframeFile);
 
    // load multiframe file
    var image = new DicomImage(multiFrameFullPathframeNumber);
    _logger.Trace(String.Format("image : loaded"));
    // get pixel data from dataset
    var sourcePixelData = DicomPixelData.Create(image.Dataset);
 
    // get frame from pixel data
    var individualFrameData = sourcePixelData.GetFrame(frameNumber);
 
            #region Generate and fill DICOM data set
 
    var dataset = image.Dataset.Clone();
    _logger.Trace(String.Format("DataSet Created"));
            #endregion // Generate and fill DICOM data set
 
    var pixelData = DicomPixelData.Create(datasettrue);
    pixelData.BitsStored = image.Dataset.Get<ushort>(DicomTag.BitsStored);
    pixelData.BitsAllocated = image.Dataset.Get<ushort>(DicomTag.BitsAllocated);
    pixelData.SamplesPerPixel = image.Dataset.Get<ushort>(DicomTag.SamplesPerPixel);
    pixelData.HighBit = image.Dataset.Get<ushort>(DicomTag.HighBit);
    pixelData.PixelRepresentation = image.Dataset.Get<PixelRepresentation>(DicomTag.PixelRepresentation);
    pixelData.PlanarConfiguration = image.Dataset.Get<PlanarConfiguration>(DicomTag.PlanarConfiguration);
    pixelData.AddFrame(individualFrameData);
 
    _logger.Trace(String.Format("pixelData Created"));
    _logger.Trace(String.Format("DataSet : {0}"dataset));
 
    var df = new DicomFile(dataset.Clone());
    using (var ms = new MemoryStream())
    {
        df.Save(ms);
        _logger.Trace(String.Format("Dataset saved"));
        return ms;
    }
}



Chris Horn

unread,
Sep 3, 2014, 6:10:41 PM9/3/14
to fo-d...@googlegroups.com
Sorry I should explain a bit more about the second function.

So in our legacy system we used naming conventions (for better or worse, people didn't trust things existing in Dicom, back then) and for Multi-frames we prefixed the file name with "Multi-"
We have another function that when called returns a list of Dicom files for a series or study when that encounters a file with "Multi-" it creates Virtual file name eg.

Dicom0573-FRAME0001.dcm

This file name can then be sent into function 2 above.

Hope it helps

Matias

unread,
Sep 4, 2014, 2:08:12 PM9/4/14
to fo-d...@googlegroups.com
Hi Chris,

thanks for your answers, it really helps.

I have a single DICOM File with around 168 frames in it so I was looking for a way to save individual DICOM Images, that is, extracting each frame and generating 168 DICOM files..

Thanks,

Matias.

barna...@gmail.com

unread,
Nov 4, 2021, 3:33:46 PM11/4/21
to Fellow Oak DICOM
Log manager doesn't have a definition for GetCurrentClassLogger(). How can I change the code in order to work?
I use Fo-Dicom version 5.0.0
Capture.JPG

Thanks
Reply all
Reply to author
Forward
0 new messages