Matlab:将多个Dicom文件保存为jpeg或png格式

时间:2017-03-20 21:34:20

标签: matlab image-processing save png dicom

我可以阅读Dicom格式文件并使用imshow()显示它。然后,我可以使用saveas选项将文件保存到jpeg或png中。这适用于一次一个文件。但是,我有大约1000个这样的dicom文件。如何将多个dicom数据文件以jpeg格式保存到另一个文件夹中?

这是我一次读取一个文件的方式:

 X = dicomread('C:\Users\skm\Desktop\DicomRaw\578A0BF9');
imshow(X);
%Then from the figure I go to saveas option to save the file as jpeg.

这是我为多个文件尝试的内容

%read multiple images

FileList = dir('C:\Users\skm\Desktop\DicomRaw\*.*');
Converted_jpeg = dir('C:\Users\skm\Desktop\Jpeg_file\*.*');

N = size(FileList,1);

for k = 1:N

   % get the file name:
   filename = FileList(k).name
   disp(filename);

end

pic

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码示例:

indir = 'C:\Users\skm\Desktop\DicomRaw\';  %Input folder name with DICOM files.
outdir = 'C:\Users\skm\Desktop\Jpeg_file\'; %Output folder name for storing jpg files.
FileList = dir([indir, '*.*']); %Get list of all files in input folder.

for k = 1:N
    % get the file name:
    filename = FileList(k).name;

    %Verify there is no dot in file name (in case folder contains other files).
    if (~any(filename == '.'))
        X = dicomread([indir, filename]);

        %Add .jpg extension to file name
        out_filename = [filename, '.', 'jpg'];

        %Use imwrite for saving (better than using imshow and saveas).
        imwrite(X, [outdir, out_filename]);
    end
end