MATLAB Answers

Avoid for loop to increase processing in image processing.

1 view (last 30 days)
I have three matrices
labelism is nr x nc binary matrix
colorim is nr x nc x 3 RGB matrix
and skin_img is also nr x nc x 3 RGB matrix with initially all the zeros on it (black image)
I want to use the labelism matrix to create skin_img matrix from colorim matrix.
Following is the code giving perfectly fine answer
for i = 1:nr
for j = 1:nc
if (labelim(i,j) == 1)
skin_img(i,j,:) = colorim(i,j,:);
But it is slow for big size images. Is there any way to avoid for loop?


Sign in to comment.

Accepted Answer

Alex Mcaulley
Alex Mcaulley on 10 Jul 2019
Edited: Alex Mcaulley on 10 Jul 2019
It is just masking your RGB image. Isn't it?
skin_img = repmat(labelism,[1,1,3]).*colorim;

  1 Comment

Muhammad Farhan  Mughal
Muhammad Farhan Mughal on 10 Jul 2019
Thank you Alex, yes it was about masking. The processing speed has increased a lot.
Thanks again

Sign in to comment.

More Answers (0)