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

18 vues (au cours des 30 derniers jours)
Suba Suba
Suba Suba le 15 Sep 2016
Commenté : ismail tepedag le 23 Mai 2021
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 commentaire
ismail tepedag
ismail tepedag le 23 Mai 2021
try below trick
b=mat2gray(output_image);
d=im2uint8(b);
new image is d without loosing much details...

Connectez-vous pour commenter.

Réponses (2)

Gopichandh Danala
Gopichandh Danala le 16 Sep 2016
% 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 commentaires
Suba Suba
Suba Suba le 19 Sep 2016
Yea,Okey.Thank you.
ismail tepedag
ismail tepedag le 23 Mai 2021
  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 !

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 16 Sep 2016
Modifié(e) : Walter Roberson le 17 Sep 2016
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 commentaire
Suba Suba
Suba Suba le 17 Sep 2016
Thank you for the useful links and information, I will refer those links.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by