How to convert tif stack to dcm series?
Ältere Kommentare anzeigen
I have a tif file that contains 1813 pages (images). I want to convert these to DICOM files within a single series. Currently, the code I am using writes over the .dcm file during each loop. How can I fix this?
fname = 'Sample19.tif';
info = imfinfo(fname);
imageStack = [];
numberOfImages = length(info);
for k = 1:numberOfImages
currentImage = imread(fname, k, 'Info', info);
dicomwrite(currentImage,'gear.dcm')
imageStack(:,:,k) = currentImage;
end
1 Kommentar
Amine Adjoud
am 16 Nov. 2022
I encouter the same problem. Did you find a solution?
Antworten (1)
Walter Roberson
am 10 Aug. 2020
fname = 'Sample19.tif';
info = imfinfo(fname);
imageStack = [];
numberOfImages = length(info);
for k = 1:numberOfImages
currentImage = imread(fname, k, 'Info', info);
imageStack(:,:,k) = currentImage;
end
dicomwrite(imageStack,'gear.dcm')
However, in practice you almost always need a bunch of dicom metadata. The easiest way to get that is to use dicominfo() on a dcm file that has the same kind of attributes that you are going to need, and pass the resulting metadata to dicomwrite after the file name.
8 Kommentare
Alena Schwartz
am 10 Aug. 2020
Walter Roberson
am 10 Aug. 2020
Please post the content of otherinfo
Alena Schwartz
am 10 Aug. 2020
Alena Schwartz
am 10 Aug. 2020
Walter Roberson
am 10 Aug. 2020
Sorry, I do not know at the moment. That is the sort of thing where I would want to use a debugger to figure out why it cannot determine the photometric interpretation.
TransferSyntaxUID: '1.2.840.10008.1.2.4.91'
ImageComments: 'JPEG 2000 lossless - Version 4.0.2 (c) Image Devices GmbH'
That is odd. Transfer Syntax 1.2.840.10008.1.2.4.91 is JPEG 2000 Image Compression, not lossless -- lossless is 1.2.840.10008.1.2.4.90, or 1.2.840.10008.1.2.4.92 (multicomponent)
Julianna Mather
am 28 Sep. 2020
Here are a couple of things to try/keep in mind:
- Use dicomwrite(img, filename, 'CreateMode', 'copy', info) to preserve as much metadata (in info) as possible.
- To make all of the images be part of the same series and study, use dicomuid to create a couple of UIDs and update the metadata fields info.SeriesInstanceUID and info.StudyInstanceUID.
- You'll need to update the info.ImagePositionPatient metadata value for each slice, otherwise they'll all be on top of each other. The field specifies the (x/y/z) location of the upper-left pixel in the patient coordinate system (measured in milimeters). If you know the stepping in the Z direction, this should be easy to compute and update for each loop. If not, you'll have to make something up.
- For broader compatibility, it might be a good idea to try to use a transfer syntax other than JPEG-2000. Consider setting info.TransferSyntaxUID to 1.2.840.10008.1.2.5 (for RLE lossless) or 1.2.840.10008.1.2.4.57 (for JPEG lossless).
I admit, this could be a little simpler.
Amine Adjoud
am 16 Nov. 2022
I encouter the same problem, did you get a solution?
Braian Adair
am 20 Feb. 2024
Thank you Julianna Mather you solved my four days problem!
Kategorien
Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!