我正在尝试使用label2rgb生成RGB标签切片并使用它来更新RGB卷,如下所示:
labelRGB_slice=label2rgb(handles.label(:,:,handles.current_slice_z), 'jet', [0 0 0]);
handles.labelRGB(:,:,handles.current_slice_z) = labelRGB_slice;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
**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;
Run Code Online (Sandbox Code Playgroud)
调试时我得到这个:
size(labelRGB_slice)
ans =
160 216 3
K>> size(handles.labelRGB(:,:,handles.current_slice_z) )
ans =
160 216
Run Code Online (Sandbox Code Playgroud)
我像这样声明handle.labelRGB:
handles.labelRGB = zeros(dim(1), dim(2), dim(3), 3);
Run Code Online (Sandbox Code Playgroud)
所以我不明白指数差距.
如何使切片分配工作?
根据您声明的方式,handles.labelRGB它是一个大小为4D的数组,[160 216 3 3]但是您使用handles.labelRGB(:,:,handles.current_slice_z)这种方式将其索引为3D数组,这意味着matlab将使用最后两个维度的线性索引.因此,如果handles.current_slice_z = 5它返回handles.labelRGB(:,:,2,2)哪个是大小矩阵[160 216].所以根据handles.current_slice_z你的意思要么需要使用
handles.labelRGB(:,:,:,handles.current_slice_z) = labelRGB_slice;
Run Code Online (Sandbox Code Playgroud)
要么
handles.labelRGB(:,:,handles.current_slice_z,:) = labelRGB_slice;
Run Code Online (Sandbox Code Playgroud)