필터 지우기
필터 지우기

How would you create a mask on an image?

조회 수: 1 (최근 30일)
Feynman
Feynman 2013년 10월 5일
댓글: Image Analyst 2013년 10월 5일
I am doing a project and one of the tasks is to create a matrix with number of pixels x number of pixels x 3 as its size. In the previous task I created a matrix using the green container of the RGB image and I am suppose to duplicate this along the 3 dimensions. My question is what functions would I use in order to do this. I am not allowed to use any implicit functions only explicit.
  댓글 수: 6
Feynman
Feynman 2013년 10월 5일
I tried implementing the code you suggested and it keeps giving me an error of integers can only be combined with integers of the same class or scale doubles
Image Analyst
Image Analyst 2013년 10월 5일
mark and redChannel have to be the same type of integer like it said. So you'd need to do
maskedRed = redChannel .* uint8(mask);
if redChannel is a uint8.

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

채택된 답변

Image Analyst
Image Analyst 2013년 10월 5일
Here's one method:
% Multiply the mask by each color channel individually.
maskedRed = redChannel .* mask;
maskedGreen = greenChannel .* mask;
maskedBlue = blueChannel .* mask;
% Recombine separate masked color channels into a single, true color RGB image.
maskedRgbImage = cat(3, maskedRed, maskedGreen, maskedBlue);
Here's another method, suggested by Sean D.
% Mask the image.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask,class(rgbImage)));

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 10월 5일
repmat() or cat(3,X,X,X)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by