在矩阵matlab中制作nan条

Make strip of nan in a matrice matlab

我有一个图像大小 (m x n x 4) 我想在上面制作 0NaN 的条带。我希望条带宽度为 4 像素,并且它们之间的 space 约为 30 像素。那就是当我在 RGB 中显示图像时,我有 NaN 条带。有人可以帮我解决这个问题吗?

我将你的问题解释为 "how can I repeatedly draw black lines with a given width and a specified offset over an image"。

img = imread('peppers.png');
height = size(img,1);
strip_width = 4;
strip_offset = 30;

line_start_idx = 0:(strip_width+strip_offset):height;
line_idx = ndgrid(line_start_idx,1:strip_width)';
line_idx = line_idx(:);
line_add = repmat(1:strip_width,1,length(line_start_idx))';
line_idx = line_idx + line_add;

img(line_idx,:,:) = 0;
imshow(img)