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 CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by