I have implemented a function to do this already, but I don’t like the necessity for a loop. I don’t see any way to avoid the loop however. Curious if there is a better way to do this.
function [ colored_img ] = colorImg ( img, ix, c )
% function [ colored_img ] = colorImg ( img, ix, c )
%
% INPUTS
% img - a 3D array representing the image to color.
% ix - the indexes of the pixels to set to a new color.
% c - a vector representing the color to paint the pixels ix.
%
% OUTPUTS
% colored_img - the colored image.
colored_img = img;
for jx = 1 : numel(c);
a = colored_img(:,:,jx);
a(ix) = c(jx);
colored_img(:,:,jx) = a;
end
end
You can just replicate the indices for the colors.