필터 지우기
필터 지우기

How to apply same 2D logical mask to each 3D layer effctively?

조회 수: 7 (최근 30일)
JAI PRAKASH
JAI PRAKASH 2018년 7월 13일
댓글: Walter Roberson 2018년 7월 14일
RGB = imread('onion.png');
mask = RGB(:,:,1)>100;
%%How can I do something like below
RGB(mask,1:3) = 0; % I want to apply same 2D 'mask' for all the 3 layers
I got this intuition from this post "logical operation on a column within a matrix" .

답변 (1개)

Image Analyst
Image Analyst 2018년 7월 13일
Try this:
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
  댓글 수: 7
Image Analyst
Image Analyst 2018년 7월 13일
It might be slightly faster but it's not general. It's depending on there being at least some red in every pixel of Im2 that you want to use as a mask. So it won't work for a general color where the shape in Im2 could be anything but would work in your specific computer graphics case.
Walter Roberson
Walter Roberson 2018년 7월 14일
Using the multiply version can be faster sometimes because the multiply version on sufficiently large matrices can be sent to LAPACK for multithreaded execution.

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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by