Error while reading DICOM images in simple program

I am newbie to MATLAB, I was trying simple example given here. Code:
% Preallocate the 256-by-256-by-1-by-20 image array.
X = repmat(int16(0), [256 256 1 20]);
% Read the series of images.
for p=1:20
filename = sprintf('brain_%03d.dcm', p);
X(:,:,1,p) = dicomread(filename);
end
% Display the image stack.
montage(X,[]);
I am getting error as :
Error using montage>validateColormapSyntax (line 339)
An indexed image can be uint8, uint16, double, single, or logical.
Error in montage>parse_inputs (line 259)
cmap = validateColormapSyntax(I,varargin{2});
Error in montage (line 114)
[I,cmap,mSize,indices,displayRange,parent] = parse_inputs(varargin{:});
Error in main (line 11)
montage(X,[]);
What I am doing wrong here? When I comment montage(), it runs without any error. Thanks for you time.

 採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 20 日

1 投票

If the data signed 16 bit like you seem to indicate, then you will need to use
X = zeros(256, 256, 1, 20);
If the data is unsigned 16 bit then you can use
X = zeros(256, 256, 1, 20, 'uint16');

6 件のコメント

Nitinkumar Ambekar
Nitinkumar Ambekar 2015 年 12 月 20 日
I tried both lines by adding after repmat(), I am not getting results as expected. By using
X = zeros(256, 256, 1, 20);
I get
And using
X = zeros(256, 256, 1, 20, 'uint16');
I get black image. Thanks @Walter Roberson
Nitinkumar Ambekar
Nitinkumar Ambekar 2015 年 12 月 20 日
I am getting :
Warning: Image is too big to fit on screen; displaying at 50%
In imshow (line 309)
In montage (line 152)
In main (line 17)
Is this the cause of getting such result?
Walter Roberson
Walter Roberson 2015 年 12 月 20 日
You should use the 'Size' option of montage()
montage(X, 'Size', [4 5])
Could you tell me what min(X(:)) and max(X(:)) are?
Nitinkumar Ambekar
Nitinkumar Ambekar 2015 年 12 月 20 日
編集済み: Nitinkumar Ambekar 2015 年 12 月 20 日
I tried 'size', getting same output
min(X(:)) is 0
max(X(:)) is 1059
Nitinkumar Ambekar
Nitinkumar Ambekar 2015 年 12 月 20 日
Thanks Walter Roberson, I changed the following and it works now!
$montage(X,[]); %Old which doesnt work
montage(X,'displayrange',[]);
Walter Roberson
Walter Roberson 2015 年 12 月 21 日
With that maximum you could use uint16()

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by