How to convert DICOM image to JPEG/PNG with out loosing it's metadata?

20 次查看(过去 30 天)
I need to convert my dicom image to jpg or png format without loosing it's meta data,I have already refered this link,but the solution given on that link is not working at all,cannot save the image as jpg. Please suggest some links or code to this conversion.

回答(2 个)

Gopichandh Danala
Gopichandh Danala 2016-9-16
% code
% 793 is a dicom image
DICOM_image = dicomread('793');
info = dicominfo('793');
window_center = info.WindowCenter;
window_width = info.WindowWidth;
rescale_slope = info.RescaleSlope;
rescale_intercept = info.RescaleIntercept;
low = abs(info.RescaleIntercept)-abs(info.WindowCenter)+30;
high = low+info.WindowWidth;
figure, imshow(DICOM_image, [low high]);
[nrows, ncols] = size(DICOM_image);
output_image = zeros(size(DICOM_image));
new_image = zeros(nrows, ncols);
max_pixel_intensity = 255;
for i = 1:nrows
for j = 1:ncols
new_image(i, j) = DICOM_image(i, j) * rescale_slope + rescale_intercept;
if (new_image(i, j) < (window_center - window_width / 2))
output_image(i, j) = 0;
else if (new_image(i, j) > (window_center + window_width / 2))
output_image(i, j) = max_pixel_intensity;
else
output_image (i, j) = (max_pixel_intensity / window_width) * (new_image(i, j) + window_width / 2 - window_center);
end
end
end
end
output_image = uint8(output_image);
figure, imshow(output_image);
imwrite(output_image,'converted.jpg');
Hope it helps, Let me Know
  7 个评论
ismail tepedag
ismail tepedag 2021-5-23
  1. What is 30 ? it works but why ?
low = abs(info.RescaleIntercept)-abs(info.WindowCenter)+30;
2. +window_width/2 shall not be existing in below code.
output_image (i, j) = (max_pixel_intensity / window_width) * (new_image(i, j) + window_width / 2 - window_center);
Have nice day !

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2016-9-16
编辑:Walter Roberson 2016-9-17
It is not possible to convert DICOM to JPG or PNG without losing metadata.
For JPEG files you could convert convert the metadata to some kind of string encoding, and then include it in the file as an EXIF "Description" field, provided that the encoding of the metadata does not occupy more than 64 Kb; see https://en.wikipedia.org/wiki/Exif
PNG does not have EXIF. You can, though, encode arbitrary metadata as name=value strings; see http://stackoverflow.com/questions/9542359/does-png-contain-exif-data-like-jpg -- or at least you could in theory, as imwrite() does not support that. You could, though, instead use the same technique as described above, encoding the metadata as strings (somehow) and then use imwrite() to PNG with the 'Description' name/value pair.
Working out how to convert all of the metadata to strings that could later be parsed would be up to you.

类别

Help CenterFile Exchange 中查找有关 DICOM Format 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by