Is there a way to overlay one mask onto another?

조회 수: 8 (최근 30일)
Teshan Rezel
Teshan Rezel 2021년 8월 4일
편집: Teshan Rezel 2021년 8월 4일
I have two masks, as below. I want to make sure that the white area of the second mask is not more than the white in the first. Is there a way to overlay mask 1 over mask 2?
In other words, mask 1 is the mnaximum possible size of the obejct of interest, whilst mask 2 is guaranteed to be smaller than mask 1. Mask 2, however, has artifacts (remnants of the background from thresholding). I would like to "screen out" the background from mask 2, to overlay the black elements of mask 1 onto mask 2 so that mask 2 is at most as big as mask 1.
  댓글 수: 2
the cyclist
the cyclist 2021년 8월 4일
Can you upload the two image files?
Teshan Rezel
Teshan Rezel 2021년 8월 4일
@the cyclist done, thanks!

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

채택된 답변

the cyclist
the cyclist 2021년 8월 4일
I don't really do image processing, but I think this straightforwardly answers your question, using only base MATLAB commands. There might be simpler ways, using the Image Processing Toolbox.
% Upload the image
image1 = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/703072/1.png');
image3 = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/703077/3.png');
% Check if a pixel is white (i.e. all values are 255)
isWhitePixel1 = all(image1==255,3);
isWhitePixel3 = all(image3==255,3);
% Count the number of white pixels in each image
numberWhitePixels1 = sum(isWhitePixel1(:));
numberWhitePixels3 = sum(isWhitePixel3(:));
% Because the image are different sizes, calculate the fraction of the
% image that is white rather than the pixel count.
fractionalWhiteArea1 = 3*numberWhitePixels1/prod(size(image1))
fractionalWhiteArea1 = 0.9499
fractionalWhiteArea3 = 3*numberWhitePixels3/prod(size(image3))
fractionalWhiteArea3 = 0.9601
You can see that image 1 has about 95% white area, and image 3 has about 96%. Note that image 3 has some gray values ([191,191,191]), but image 1 has only black and white.
  댓글 수: 1
Teshan Rezel
Teshan Rezel 2021년 8월 4일
@the cyclist Thanks for this! Apologies, I must not have been very clear in my question. I'll rephrase it to clarify!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by