📄 write_dicom.m
字号:
function status = write_dicom(in_filename, out_filename)
% WRITE_DICOM read in an image file,and output a DICOM file.
% in_filename is the input file's name,in_filename supporting
% BMP,JPEG,PNG,GIF,TIFF,PPM,and so on.
% out_filename is the output dicom file's name.usually, you should suffix
% out_filename with '.dcm' explicitly.
% because this matlab script is coded for idea provement,so there isn't any
% warranty.pleaz report any bug to ybc2084@163.com or
% submit on my blog:www.dormforce.net/blog/rockins.
info = imfinfo(in_filename);
M = info.Height;
N = info.Width;
if strcmp(info.ColorType, 'indexed')
[X,MAP] = imread(in_filename);
status = dicomwrite(X, MAP, out_filename);
% RGB = ind2rgb(X, MAP);
% status = dicomwrite(RGB, out_filename);
elseif (strcmp(info.ColorType, 'grayscale') || strcmp(info.ColorType, 'truecolor'))
X = imread(in_filename);
status = dicomwrite(X, out_filename);
end
% build metadata
% metadata.Format = 'DICOM';
% metadata.FormatVersion = 3;
% metadata.Width = N;
% metadata.Height = M;
% metadata.BitDepth = info.BitDepth;
% metadata.ColorType = info.ColorType;
% write out dicom image and metadata
% if strcmp(info.ColorType, 'indexed')
% RGB = ind2rgb(X, MAP);
% dicomwrite(RGB, out_filename);
% else
% status = dicomwrite(X, out_filename);
% end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -