FDetect = vision.CascadeObjectDetector;
%// Read the input image
I = imread('face.jpg');
%// Returns Bounding Box values based on number of objects
BB = step(FDetect,I);
figure,
imshow(I);
hold on
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',2.5,'LineStyle','','EdgeColor','r');
end
title('Face Detection');
hold off;
过滤器:
E = imerode(I,strel('square',5));
figure, imshow(E);
我的问题是如何仅在IN矩形面区域中提供滤镜。
答案 0 :(得分:1)
您需要仅提取图像中位于边界框内的区域,然后仅对该部分应用imerode
操作。
边界框的形式为[x,y,width,height]。我们需要将其转换为像素。
%// Ensure that we are working with integers.
BB(k,:) = round(BB(k,:));
%// Sample all rows and columns within this bounding box
rows = BB(k,2):sum(BB(k,[2 4]))
cols = BB(k,1):sum(BB(k,[1 3]))
%// Apply the imerode operation on just these pixels
I(rows,cols) = imerode(I(rows,cols), strel('square', 5));