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

3 ビュー (過去 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 件)

カテゴリ

Help Center および File ExchangeModify Image Colors についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by