How to assign rgb values to multiple row,col of a matrix ?
1 次查看(过去 30 天)
显示 更早的评论
for i=1:2%max(label(:))
[rows, cols] = find(label == i);
image(rows,cols,:) = [0,0,0];
end
but I get the error subscripted assignment dimension mismatch
0 个评论
回答(2 个)
Guillaume
2017-1-17
If the R, G and B values are identical:
image(sub2ind(size(image), repmat(rows, 1, 3), repmat(cols, 1, 3), repmat([1 2 3], numel(rows), 1)) = 0;
If not,
image(sub2ind(size(image), repmat(rows, 1, 3), repmat(cols, 1, 3), repmat([1 2 3], numel(rows), 1)) = repmat([R G B], numel(rows), 1);
unfortunately, neither is particularly straightforward.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!