根据 MA​​TLAB 中的切片归一化 3D 图像

Normalization 3D Image according to Slices in MATLAB

我有一个矩阵 256X192X80。我想在不使用 for 循环的情况下标准化所有切片(80 代表切片)。 我使用 for 的方式如下:(im_dom_raw 是我们的矩阵)

normalized_raw = zeros(size(im_dom_raw));
for a=1:80
   slice_raw = im_dom_raw(:,:,a);
   slice_raw = slice_raw-min(slice_raw(:));
   slice_raw = slice_raw/(max(slice_raw(:)));
   normalized_raw(:,:,a) = slice_raw; 
end

下面的代码在不使用循环的情况下实现了您的规范化方法。它基于 bsxfun.

% Shift all values to the positive side
slices_raw = bsxfun(@minus,im_dom_raw,min(min(im_dom_raw)));

% Normalize all values with respect to the slice maximum (With input from @Daniel)
normalized_raw2 = bsxfun(@mrdivide,slices_raw,max(max(slices_raw)));

% A slightly faster approach would be
%normalized_raw2 = bsxfun(@times,slices_raw,max(max(slices_raw)).^-1);
% ... but it will differ with your approach due to numerical approximation

% Comparison to your previous loop based implementation
sum(abs(normalized_raw(:)-normalized_raw2(:)))

最后一行代码输出

ans =

0

这(感谢@Daniel)意味着两种方法产生完全相同的结果。