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

14 ビュー (過去 30 日間)
Suba Suba
Suba Suba 2016 年 9 月 15 日
コメント済み: ismail tepedag 2021 年 5 月 23 日
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.
  1 件のコメント
ismail tepedag
ismail tepedag 2021 年 5 月 23 日
try below trick
b=mat2gray(output_image);
d=im2uint8(b);
new image is d without loosing much details...

サインインしてコメントする。

回答 (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 件のコメント
Suba Suba
Suba Suba 2016 年 9 月 19 日
Yea,Okey.Thank you.
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.
  1 件のコメント
Suba Suba
Suba Suba 2016 年 9 月 17 日
Thank you for the useful links and information, I will refer those links.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDICOM Format についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by