dicomwrite to save dicom image with window level setting

조회 수: 23 (최근 30일)
mohd akmal masud
mohd akmal masud 2021년 8월 18일
댓글: Walter Roberson 2021년 9월 1일
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
dicomwrite(T, 'S.dcm');
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,
dictionary);
Error in dicom_prep_metadata (line 51)
metadata = dicom_prep_ImagePixel(metadata, X, map, txfr,
useMetadataBitDepths, dictionary);
Error in dicom_create_IOD (line 26)
metadata = dicom_prep_metadata(IOD_UID, metadata, X, map, options.txfr,
options.usemetadatabitdepths, dictionary);
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
Simon Chan 2021년 8월 18일
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
clear; clc;
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):
  댓글 수: 6
mohd akmal masud
mohd akmal masud 2021년 9월 1일
this is size I and cmap
>> [I, cmap] = dicomread('I10');
>> size(I)
size(cmap)
ans =
258 258 1 176
ans =
0 0
>>
Walter Roberson
Walter Roberson 2021년 9월 1일
metadata = dicominfo('I10');
WC = metadata.WindowCenter; % original [40; 40]
WW = metadata.WindowWidth; % original [80; 80] % Left figure below
metadata.WindowCenter = [1200; 1200];
metadata.WindowWidth = [400; 400];
I = dicomread(metadata);
imshow3D(permute(I,[1 2 4 3])); %look for the WL and best picture
for k = 1:size(I,4)
dicomwrite(I(:,:,:,k),sprintf('%d.dcm',k), metadata, 'CreateMode', 'copy');
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 8월 18일
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()

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by