Avoid for loop to increase processing in image processing.

조회 수: 5 (최근 30일)
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,:);
end
end
end
imshow(uint8(skin_img));
But it is slow for big size images. Is there any way to avoid for loop?

채택된 답변

Alex Mcaulley
Alex Mcaulley 2019년 7월 10일
편집: Alex Mcaulley 2019년 7월 10일
It is just masking your RGB image. Isn't it?
skin_img = repmat(labelism,[1,1,3]).*colorim;
  댓글 수: 1
Muhammad Farhan  Mughal
Muhammad Farhan Mughal 2019년 7월 10일
Thank you Alex, yes it was about masking. The processing speed has increased a lot.
Thanks again

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by