Hi all, I am trying to convert DICOM images in PGM images for a software I am using. dicomread() reads them correctly, but when it comes to use imwrite(), it provides PBM images (I check it using Mac infos, and using the fact that on the program I am writing gives me an error when I use those images, a wrong-extension-error). Note that if I try other formats like png it works.
The code is the following:
clear all; close all; clc;
MM = 1686; 
mm = -2048; 
for ii=1:331
    str = strcat('/my/path/IM-0001-',num,'-0001.dcm');  
    info = dicominfo(str,'UseDictionaryVR',true);       
    Y = double(dicomread(info));                        
    Y = (Y-mm)./(MM-mm);                                
    titleSlice = strcat('/my/path/slice',num2str(ii),'.pgm');  
    imwrite(Y,titleSlice,'pgm');                        
end