Replace an image with other one

86 views
Skip to first unread message

Helder Cesar

unread,
Jun 26, 2015, 12:50:37 PM6/26/15
to fo-d...@googlegroups.com
Hi!

I want to replace an image of an dicom file for an image of other dicom file.
After opening both files, _file1 and _file2, what I'm doing is:

    DicomFile new_dicom = _file1;
   
DicomImage img = new DicomImage(_file1.Dataset);
           
    new_dicom
.Dataset.Remove(DicomTag.PixelData);
    new_dicom
.Dataset.Add(DicomTag.PixelData, img.PixelData);

    new_dicom
.Save("newfile.dcm");

For some reason, the program stops at line 5 (...Add(DicomTag.PixelData...)
What am I doing wrong?
Comments and suggestions are welcome.

Thank you.

Matias

unread,
Jun 26, 2015, 1:12:32 PM6/26/15
to fo-d...@googlegroups.com
So you want to create a copy of an image in disk?

Helder Cesar

unread,
Jun 27, 2015, 8:31:03 AM6/27/15
to fo-d...@googlegroups.com
Actually I want to copy all header information of one file to another one.
Since I didnt find any way to copy the header in a single way, I supposed is easier to copy the image of one to another...

Matias

unread,
Jun 27, 2015, 10:33:48 AM6/27/15
to fo-d...@googlegroups.com
  Try this:
         DicomImage img = new DicomImage(_file1.Dataset);
                DicomFile archivodicom = new DicomFile();
                archivodicom = new DicomFile(img.Dataset);
                archivodicom.Save("newfile.dcm");

Helder Cesar

unread,
Jun 28, 2015, 8:57:17 AM6/28/15
to fo-d...@googlegroups.com
Hi.

Sorry but, this code doesnt make any sense!

For example, in the code below You already have a new instance of DicomFile, why should you do another new instance based on img.Dataset?


DicomFile archivodicom = new DicomFile();
archivodicom
= new DicomFile(img.Dataset);


Look, perhaps I didnt make myself clear:

This is the situation:

_file1;
_file2;

_newfile = _file2;

// Copy Image from _file1 to _newfile. So this _newfile will have the header of _file2 but the image of _file1.

_newfile.Save("newfile.dcm");

Reply all
Reply to author
Forward
0 new messages