如何将DICOM文件转换为RGB?

发布于 2025-02-12 19:23:36 字数 829 浏览 4 评论 0原文

我将在MATLAB中解释我的问题。我有一个多帧DICOM文件,70x70x50。我想将其转换为RGB。

这是我的代码:

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

这是错误:

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);

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说谎友 2025-02-19 19:23:36

您需要在colored_mha上引用额外的维度。

尝试:

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

更普遍 - 错误告诉您,您正在尝试将大一些东西放入太小的东西中,当您看到这一点时,您可以问自己为什么。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文