1
votes

I have 110 CT dicom images, and their names are randoms, so when I display them using any dicom viewer, they are displayed randomly. Thus I am trying to rename these dicom images according to their Image Number (0020,0013) or Slice Location (0020,1041). I have already started to write a script

image_list=dir('*.dcm');
 for i=1:25
    img=dicomread(image_list(i).name);
    imgHdr = dicominfo(image_list(i).name);
 dicomwrite(img, ['T' num2str(i) '.dcm'], imgHdr,'CreateMode','Copy')
end

But I don't know how to tell it check the InstanceNumber and use it in the new name ?

2
I used a .dcm provided by MatLab (info = dicominfo('CT-MONO2-16-ankle.dcm') and I did not find Image Number within the info provided by dicominfo. What do you mean with check the image number ?il_raffa
@il_raffa Sorry, I meant InstanceNumber in Matlab (Image Number in imageJ)Turki

2 Answers

3
votes

The InstanceNumber is accessible as an element of the dicominfo output struct:

instancenumber = ImgHdr.InstanceNumber;

And I would construct the filename using sprintf

outputfilename = sprintf('T%04d', instancenumber);

There are many formats for sprintf mirroring those from C++'s printf, The ones I used above print an integer (the 'd') with 4 digits (the '4'), zero padded (the '0'). This is good for automatic sorting by file managers. If you need a different format check the docs here.

0
votes

I think you only need to add the following line to your script:

imgHdr.InstanceNumber = i;

and try to load the images in a viewer.