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

Réponses (1)

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()

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Centre d'aide et File Exchange

Question posée :

le 26 Nov 2016

Réponse apportée :

DGM
le 20 Mar 2023

Community Treasure Hunt

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

Start Hunting!

Translated by