I'm new to DICOM and to fo-dicom
library. I'm trying to create a DICOM file out of an OCT eye scan video. First I'm extracting of the frames of the video and then create a DICOM file using fo-dicom
.
public static void CreateDicomFromVideo(string path)
{
List<Bitmap> videoFrames = GetVideoFrames(path);
CreateDicomFromFrames(videoFrames);
}
private static List<Bitmap> GetVideoFrames(string path)
{
List<Bitmap> videoFrames = new List<Bitmap>();
using (var vFReader = new VideoFileReader())
{
vFReader.Open(path);
for (int i = 0; i < vFReader.FrameCount; i++)
{
Bitmap bmpBaseOriginal = vFReader.ReadVideoFrame();
videoFrames.Add(bmpBaseOriginal);
}
vFReader.Close();
}
if (videoFrames.Count > 0)
return videoFrames;
else return null;
}
private static void CreateDicomFromFrames(List<Bitmap> videoFrames)
{
DicomDataset dataset = new DicomDataset();
FillDataset(dataset);
int i = 0;
foreach (Bitmap item in videoFrames)
{
Bitmap bitmap = new Bitmap(item);
bitmap = GetValidImage(bitmap);
int rows, columns;
byte[] pixels = GetPixels(bitmap, out rows, out columns);
MemoryByteBuffer buffer = new MemoryByteBuffer(pixels);
if (i == 0)
{
dataset.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation.Rgb.Value);
dataset.Add(DicomTag.Rows, (ushort)rows);
dataset.Add(DicomTag.Columns, (ushort)columns);
dataset.AddOrUpdate(DicomTag.BitsAllocated, (ushort)8);
}
DicomPixelData pixelData = DicomPixelData.Create(dataset, true);
pixelData.BitsStored = 8;
//pixelData.BitsAllocated = 8;
pixelData.SamplesPerPixel = 3;
pixelData.HighBit = 7;
pixelData.PixelRepresentation = 0;
pixelData.PlanarConfiguration = 0;
pixelData.AddFrame(buffer);
i++;
}
DicomFile dicomfile = new DicomFile(dataset);
dicomfile.Save(@"D:\DICOM\files\Video files\dicomfile.dcm");
}
I'm expecting to receive a DICOM file with all the frames from the video, but getting a DICOM file with only one frame.
dcm
file the last one? – Thomas Ayoub