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

3 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Modify Image Colors dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by