logical indexing 3d array with 2d array

조회 수: 2 (최근 30일)
RuiQi
RuiQi 2017년 1월 17일
편집: Stephen23 2017년 1월 17일
how can i set the values of my matrix to a certain rgb value given a mask ?
image_a; %(640x480x3) uint8
mask; %(640x480x1) logical mat
image_a(mask) = cv::RGB(255,200,0);

채택된 답변

Stephen23
Stephen23 2017년 1월 17일
편집: Stephen23 2017년 1월 17일
Exactly like I showed you in your earlier identical question (Method 2):
A(mask(:,:,[1,1,1])) = value
If you have a single RGB value that you want to allocate to the masked points then use imoverlay from the image processing toolbox:
B = imoverlay(A,mask,rgb)
If you do not have the image processing toolbox then you can get much the same effect by using bsxfun:
B = bsxfun(@times,A,~mask) + bsxfun(@times,rgb,mask)
where rgb is a single triple of size 1*1*3, and both mask and rgb are of the same class as the image A.
  댓글 수: 1
James Tursa
James Tursa 2017년 1월 17일
OP has three different values he wants to set for the planes. So this is a slightly different question. E.g.,
image_a(mask(:,:,[1,1,1])) = repmat(value(:)',sum(mask(:)),1);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by