Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How come a DICOM file has zero size? #1690

Closed
rotoyo opened this issue Dec 1, 2023 · 3 comments
Closed

How come a DICOM file has zero size? #1690

rotoyo opened this issue Dec 1, 2023 · 3 comments
Labels

Comments

@rotoyo
Copy link

rotoyo commented Dec 1, 2023

I created a DICOM file with the following sources with a already compressed JPEG.
However, the Data Size of the (7FE0,0010) TAG of the created DICOM file becomes 0.

s1

However, the DICOM file contains the correct image.

s3

Because of this, some PACS may refuse to receive it.

s2

I would appreciate it if you could let me know where I am making a mistake.

[Environment]
Fellow Oak DICOM version: 4.0.7.0
OS: Windows10. 64
Platform: NET Framework 4.7.2)

[Source Code]

    private string MakeJpegDicom(Image img, string uid, int instanceNumber)
    {

                    DicomDataset ds = new DicomDataset(DicomTransferSyntax.JPEGProcess1);

                    ds.Add(DicomTag.SpecificCharacterSet, "ISO 2022 IR 149");
                    ds.Add(DicomTag.ImageType, "ORIGINAL\\PRIMARY\\OTHER");

                    ds.Add(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage);
                    ds.Add(DicomTag.SOPInstanceUID, uid + "." + instanceNumber);
                    ds.Add(DicomTag.StudyInstanceUID, uid);
                    ds.Add(DicomTag.SeriesInstanceUID, uid);
                    ds.Add(DicomTag.PatientID, _selectedPID);

                    Encoding encKor = DicomEncoding.GetEncoding("ISO 2022 IR 149");

                    ds.Add(DicomTag.InstitutionName, encKor, _hospitalName);
                    ds.Add(DicomTag.PatientName, encKor, _pName);
                    ds.Add(DicomTag.ReferringPhysicianName, encKor,  _doctor);
                    ds.Add(DicomTag.StudyDescription, encKor, _desc);

                    ds.Add(DicomTag.PatientBirthDate, _bod);
                    ds.Add(DicomTag.PatientSex, _pSex);
                    ds.Add(DicomTag.PatientAge, _age);
                    ds.Add(DicomTag.StudyDate, _stdDate);
                    ds.Add(DicomTag.SeriesDate, _stdDate);
                    ds.Add(DicomTag.AcquisitionDate, _stdDate);
                    ds.Add(DicomTag.ContentDate, _stdDate);
                    ds.Add(DicomTag.StudyTime, _stdTime);
                    ds.Add(DicomTag.SeriesTime, _stdTime);
                    ds.Add(DicomTag.AcquisitionTime, _stdTime);
                    ds.Add(DicomTag.ContentTime, _stdTime);
                    ds.Add(DicomTag.AccessionNumber, DateTime.Now.ToString("yyyyMMddhhmmss"));
                    ds.Add(DicomTag.StudyID, "");
                    ds.Add(DicomTag.SeriesNumber, 1);
                    ds.Add(DicomTag.Modality,  _modality);
                    ds.Add(DicomTag.InstanceNumber, instanceNumber);
        
                    //PixcelDate
                    ds.Add(DicomTag.Columns, (ushort)img.Width);
                    ds.Add(DicomTag.Rows, (ushort)img.Height);
                    ds.Add(DicomTag.BitsAllocated, (ushort)8);
                    ds.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation.YbrFull422.Value);//for jpeg
                     //ds.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation.RGB.Value);

                    DicomPixelData pixelData = DicomPixelData.Create(ds, true);
        
                    pixelData.SamplesPerPixel = 3;
                    pixelData.BitsStored = 8;
                    pixelData.HighBit = 7;
                    pixelData.PixelRepresentation = 0;
                    pixelData.PlanarConfiguration = 0;

                    MemoryStream stream = new MemoryStream();
                    img.Save(stream, ImageFormat.Jpeg);//Image to stream

                    byte[] bytes = stream.ToArray();//stream to byte
                    MemoryByteBuffer buffer = new MemoryByteBuffer(bytes);

                    //For OB ( Other Byte = 8bit  )
                    var fragment = new DicomOtherByteFragment(DicomTag.PixelData);
                    fragment.Fragments.Add(EmptyBuffer.Value);
                    fragment.Fragments.Add(EvenLengthBuffer.Create(buffer));

                    pixelData.AddFrame(new CompositeByteBuffer(fragment));//pixelData.AddFrame => OB (  8 byte )


                    //File Save
                    DicomFile dicomFile = new DicomFile(ds);
                    string dcmPath = GV.AppDir + "\\Page" + instanceNumber + ".dcm";
                    dicomFile.Save(dcmPath);

                    return dcmPath;

        }
@rotoyo rotoyo added the new label Dec 1, 2023
@mrbean-bremen
Copy link
Collaborator

Not sure what you mean by zero size - in your first screenshot, the size is shown as FFFFFFFF, e.g. -1, which means "undefined length" in DICOM. This is the normal length entry for compressed image data. So, the reason for this message must be something else...

@amoerie
Copy link
Collaborator

amoerie commented Dec 7, 2023

Why are you adding an empty buffer to the fragments?

fragment.Fragments.Add(EmptyBuffer.Value);

And why are you creating fragments in the first place, if you put everything in one fragment anyway.
Can't you just do this:

pixelData.AddFrame(buffer);

@gofal gofal added question and removed new labels Dec 21, 2023
@gofal
Copy link
Contributor

gofal commented May 19, 2024

closing this issue due to inactivity. If there is still a problem with the current version, please reopen this issue and provide actual informations.

@gofal gofal closed this as completed May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants