image - Pixel-wise like assignment In Matlab -


is there way assignment masked pixels same color except for-loop?

%% pick color cl = uisetcolor; %1-by-3 vector  im = ones(3, 3, 3)  / 2; % gray image  mask = rand(3, 3);  mask_idx = mask > 0.5; % create mask  %% im(mask_idx, :) = cl'; % assignment pixels color `cl` 

you making use of repmat():

%% pick color cl = uisetcolor; %1-by-3 vector im = ones(3, 3, 3)/2; % gray image mask = rand(3, 3); mask_idx = mask > 0.5; % create mask  cl_rep = repmat(cl,[sum(mask_idx(:)) 1]); im(repmat(mask_idx,[1 1 3])) = cl_rep(:); 

what have done repeat mask 3 times 3 layers of image. able match colour-vector cl has repeated. number of times repeated same amount of pixels changed, sum(mask_idx(:)).


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -