-1

I'll explain my problem in Matlab. I have a multi-frame DICOM file, 70x70x50. I would like to convert it to RGB.

This is my code:

clear all;
close all;
clc;
% Lettura Dicom

img = dicomread('provaDICOM.dcm'); % 4-D int16
info = dicominfo('provaDICOM.dcm');
img2 = squeeze(img); % 70x70x50 int16
img3 = mat2gray(img2); % 70x70x50 double
% volumeViewer(img2);

% Conversione RGB

cmap = copper(256);
numslice = size(img3,3);
colored_MHA = zeros(size(img3, 1), size(img3, 2), numslice, 3);
for slice = 1 : numslice
  colored_MHA(:,:,slice) = ind2rgb(img3(:,:,slice), cmap);
end

This is the error:

Unable to perform assignment because the size of the left side is 70-by-70 and the size of the right side is
70-by-70-by-3.

Error in Dicom (line 18)
  colored_MHA(:,:,slice) = ind2rgb(img3(:,:,slice), cmap);
Amit Joshi
  • 15,448
  • 21
  • 77
  • 141

1 Answers1

0

You need to reference an extra dimension on colored_MHA.

Try:

colored_MHA(:,:,:,slice) = ind2rgb(img3(:,:,slice), cmap);

More generally - the error is telling you that you're trying to put something big into something too small, and when you see this you can ask yourself why that is.