5

我正在尝试使用 label2rgb 生成 RGB 标签切片并使用它来更新 RGB 卷,如下所示:

    labelRGB_slice=label2rgb(handles.label(:,:,handles.current_slice_z), 'jet', [0 0 0]);


    handles.labelRGB(:,:,handles.current_slice_z) = labelRGB_slice;

我收到以下错误:

**Assignment has more non-singleton rhs dimensions than non-singleton subscripts**

Error in Tesis_GUI>drawSeedButton_Callback (line 468)
        handles.labelRGB(:,:,handles.current_slice_z) = labelRGB_slice;

调试时我得到这个:

size(labelRGB_slice)

ans =

   160   216     3

K>> size(handles.labelRGB(:,:,handles.current_slice_z) )

ans =

   160   216

我这样声明了handles.labelRGB:

handles.labelRGB = zeros(dim(1), dim(2), dim(3), 3);

所以我不明白索引差异。

如何使切片分配工作?

4

1 回答 1

6

根据您声明handles.labelRGB它是大小为 4D 数组的方式,[160 216 3 3]但是您将其索引为 3D 数组handles.labelRGB(:,:,handles.current_slice_z),这意味着 matlab 将对最后两个维度使用线性索引。因此,如果 说handles.current_slice_z = 5,它返回handles.labelRGB(:,:,2,2)which 是一个大小为 的矩阵[160 216]。所以根据handles.current_slice_z你的意思需要使用

handles.labelRGB(:,:,:,handles.current_slice_z) = labelRGB_slice;

或者

handles.labelRGB(:,:,handles.current_slice_z,:) = labelRGB_slice;
于 2013-08-26T07:55:31.577 回答