如何从具有给定角点的图像中裁剪面部分。 MATLAB [英] How to crop face section from an image with given corner points. MATLAB
问题描述
我想从图像裁剪脸部,但脸部图像不是直线/垂直对齐的。我有四个像素点来裁剪它..
问题是,
如果我将首先变换图像,之后不能使用像素点来裁剪面部部分。
或者在其他情况下我没有精确的边界框来直接使用imcrop裁剪图像,因为面部区域有些向左或向右倾斜。
四个像素点位于要裁剪的脸的前额,下巴和耳朵上。
I want to crop a face section from an image but face image is not straight/vertically aligned. I am having four pixel points to crop it.. Problem is that, If i will transform image first the pixel points cannot be used thereafter to crop the facial section out of it. Or in other case I am not having an exact bounding box to crop the image directly using imcrop as facial sections are somewhat tilted left or right. The four pixel points are at forehead , chin and ears of the face to be cropped.
推荐答案
你应该看看在 poly2mask 。此函数根据给定的x和y坐标生成蒙版图像:
You should look at poly2mask. This function produces a mask image from your given x and y coordinates:
BW = poly2mask(x,y,m,n);
其中 x
和 y
是您的坐标,生成的 BW
图片是 m
by 名词
。然后你可以使用这个 BW
图像来掩盖原始图像我
做
where x
and y
are your coordinates, and the produced BW
image is m
by n
. You can then use this BW
image to mask your original image I
by doing
I(~BW) = 0;
如果你真的想要裁剪,那么你可以获得边界框(通过 regionprops 功能或下面的代码):
If you actually want to crop, then you could get the bounding box (either through the regionprops function or the code below):
x1 = round(min(x));
y1 = round(min(y));
x2 = round(max(x));
y2 = round(max(y));
然后在使用 BW $ c后裁剪图像$ c>作为面具。
I2 = I(x1:x2,y1:y2);
希望有所帮助。
这篇关于如何从具有给定角点的图像中裁剪面部分。 MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!