Replace all rows of an array not equal to any row of another array by a particular row vector

1 次查看(过去 30 天)
I import an image and have ordered the rgb values in a n-by-3 array with columns as r, g, b respectively. This is named:
color_array
I also have 3 other row vectors that store r, g, b values for 3 different colors as:
color_1 = [r1, g1, b1];
color_2 = [r2, g2, b2];
color_3 = [r3, g3, b3];
I want to replace all the rows of my original color_array that are not equal to any of color_1, color_2 or color_3 with a fourth color:
color_4 = [r4, g4, b4];
and keep those that are equal to one of these 3 colors intact.
How can I do this as computationally fast as possible?

采纳的回答

Voss
Voss 2023-8-14
idx = ~ismember(color_array,[color_1; color_2; color_3],'rows');
color_array(idx,:) = repmat(color_4,nnz(idx),1);

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by