1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| clc;
close all;
clear all;
% Open an image.
[filename,pathname]=uigetfile('*','open');
% whether you open an image.
if isequal(filename,0)
disp('User selected Cancel.')
else
disp(['User selected ', fullfile(pathname, filename), '.'])
end
full_file = fullfile(pathname,filename);
Dic_data = dicomread(full_file);
figure; imshow(Dic_data, 'DisplayRange', []);
% the name for your image after convertion.
if isempty(strfind(full_file, '.dic'))
new_name = strcat(full_file, '.bmp');
else
[pathname, name, ext] = fileparts(full_file);
name = strcat(name, '.bmp');
new_name = fullfile(pathname, name);
end
% save the image as .bmp format.
if isa(Dic_data, 'int16')
imwrite(Dic_data,new_name,'bmp','Bitdepth',16,'Mode','lossless');
elseif isa(Dic_data, 'uint8')
imwrite(Dic_data,new_name,'bmp','Mode','lossless');
end
imshow(Dic_data,[]); |
Partager