how can i apply an oval mask to extract face region?

7 views (last 30 days)
how can i apply an oval mask to extract face region?

Answers (1)

DGM
DGM on 20 Mar 2023
Oh well if you want an oval, you're in luck. This is one way to generate oval masks.
inpict = imread('peppers.png');
[rows,cols,~] = size(inpict);
% generate a binary mask containing multiple ovals
[x y] = makeoval(60,[120 120],-60,'type','stadium');
mask = poly2mask(x,y,rows,cols);
[x y] = makeoval(80,[250 270],-100,'type','superegg');
mask = mask | poly2mask(x,y,rows,cols);
[x y] = makeoval(80,[400 120],-130,'type','ellipse','ratio',1.5);
mask = mask | poly2mask(x,y,rows,cols);
imshow(mask)
% apply the mask
outpict = im2uint8(double(mask).*im2double(inpict));
imshow(outpict)
... but if all you really want is an ellipse, just use imellipse() or drawellipse()

Community Treasure Hunt

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

Start Hunting!