function dcm2jpg()

%
% dcm2jpg
%
% Converts dicom image set to jpgs
%
% Input:
%   NONE (function will ask to pick a file in the dicom image folder)
%
% Output:
%   NONE (function will write jpgs in the dicom image folder)
%
% Dependencies:
%
%   dicomreadm imadjust im2uint8 imwrite
%   (available in image processing toolbox)
%
% Author: 
%   Ahmet Erdemir, erdemira@ccf.org, August 1, 2008.
%

[fn, pn] = uigetfile('*.*', 'pick up a dicom file');
fls = dir(pn);
n = length(fls);

for i=1:n
    try
        I = dicomread([pn fls(i).name]);
    catch
        disp([fls(i).name ' is not a dicom file.'])
        continue
    end
    % adjust image
    I = imadjust(I);
    % convert to uint8
    I = im2uint8(I);
    % write as jpg
    imwrite(I, [pn fls(i).name '.jpg'], 'jpg');
end
