-4

I know how to convert a jpg file to dcm with dicomwrite function but i need to convert all jpg files to dcm in a folder. Is it possible? If its possible is it possible to convert them with same name of jpg file? Thanks guys...

user3218867
  • 45
  • 1
  • 2
  • 9
  • First of all i don't know how to do it..im beginner :) and if i add new jpg files on this folder, will your code still work too? – user3218867 Jan 21 '14 at 11:25

1 Answers1

0

You can do as the following:

folder = 'D:\test\';
file_temp = sprintf('%s\\*.jpg', folder);
filearray = dir(file_temp);
s = max(size(filearray));
for i=1: 1: s
    imgname=strcat(folder,'\\',filearray(i).name);
    I = imread(imgname);
    dicomwrite(I, [imgname '.dcm']);
end

It will convert all jpg files to dcm files with their original names within given folder.

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174