dicomwrite to save dicom image with window level setting
34 views (last 30 days)
mohd akmal masud on 18 Aug 2021
Any one can help me?
I want to save my dicom images as dicom in right contrast.
I wrote like this
R = dicomread('1.dcm');
The image like below
then I wrote
T = imshow(R, [0 1844]);
then I want to save as new image, i wrote
But got ERROR
Error using dicom_prep_ImagePixel>getPixelStorage (line 204)
Invalid datatype for image pixels.
Error in dicom_prep_ImagePixel (line 13)
[ba, bs, hb, pr] = getPixelStorage(X, txfr, useExistingBitDepths, metadata,
Error in dicom_prep_metadata (line 51)
metadata = dicom_prep_ImagePixel(metadata, X, map, txfr,
Error in dicom_create_IOD (line 26)
metadata = dicom_prep_metadata(IOD_UID, metadata, X, map, options.txfr,
Error in dicomwrite>write_message (line 275)
[attrs, status] = dicom_create_IOD(SOP_UID, X, map, ...
Error in dicomwrite (line 211)
[status, options] = write_message(X, filename, map, metadata, options);
ANYONE KNOW HOW TO SAVE IMAGE DICOM AS 2ND PICTURE ???
Simon Chan on 18 Aug 2021
The matrix R coming from dicomread is the rawdata and you are not advised to change it.
Most probably you are only able to change the Default Window Level and Window Width in the DICOM headers. This default Window Level and Window Width are only used in application software which is able to retrieve this DICOM header information and hence display the image in an expected contrast level.
Hence, the displayed image will always be compelely black if you use image(R) instead of image(R,).
Following code provides a reference for you and you can observe the difference by usng imtool
X = dicomread('old.dcm');
metadata = dicominfo('old.dcm');
WC = metadata.WindowCenter; % original [40; 40]
WW = metadata.WindowWidth; % original [80; 80]
imtool(X,'DisplayRange',[WC(1)-WW(1), WC(1)+WW(1)]); % Left figure below
metadata.WindowCenter = [1050; 1050];
metadata.WindowWidth = [400; 400];
dicomwrite(X, 'New.dcm', metadata, 'CreateMode', 'copy');
Y = dicomread('New.dcm');
newmetadata = dicominfo('New.dcm');
newWC = newmetadata.WindowCenter;
newWW = newmetadata.WindowWidth;
imtool(Y,'DisplayRange',[newWC(1)-newWW(1), newWC(1)+newWW(1)]); % Right figure below
Use the original Window Level and Window Width (Left), and revised WL & WW (right):
More Answers (1)
Walter Roberson on 18 Aug 2021
T = imshow(R, [0 1844]);
the result of imshow() is a handle to a graphics image() object. You cannot write a graphics handle as an image.
You should use rescale(); older MATLAB would have to use the obscurely-named mat2gray()