Pixeling only detected face
이전 댓글 표시
% Read image
A = imread('lena512c.bmp');
%Get FaceDetector object
FaceDetector = vision.CascadeObjectDetector();
%Use FaceDetector
BBOX = step(FaceDetector, A);
%Annotation of faces
B = insertObjectAnnotation(A,'rectangle', BBOX, 'Face');
imshow(B),title('Detected Faces');
%Display number of faces
n = size (BBOX,1);
str_n = num2str(n);
str = strcat ('Number of detected faces are = ',str_n);
disp(str);
How can i pixelate just face which was detected,not whole image please?
Detector Works fine.
채택된 답변
추가 답변 (1개)
Ameer Hamza
2020년 4월 10일
편집: Ameer Hamza
2020년 4월 10일
try this
% Read image
A = imread('lena_std.tif');
%Get FaceDetector object
FaceDetector = vision.CascadeObjectDetector();
%Use FaceDetector
BBOX = step(FaceDetector, A);
%Annotation of faces
B = insertObjectAnnotation(A,'rectangle', BBOX, 'Face');
imshow(B),title('Detected Faces');
%Display number of faces
n = size (BBOX,1);
str_n = num2str(n);
str = strcat ('Number of detected faces are = ',str_n);
disp(str);
x = BBOX(1);
y = BBOX(2);
w = BBOX(3);
h = BBOX(4);
face = A(y:y+h, x:x+w, :);
sz = size(face, [1 2]);
face = imresize(imresize(face, sz/20), sz, 'Method', 'nearest');
A(y:y+h, x:x+w, :) = face;
imshow(A)

댓글 수: 8
Martin Schlachta
2020년 4월 10일
Ameer Hamza
2020년 4월 10일
I think this is the issue with the face detection algorithm, not the pixelating. The face detection did not correctly identify the bounding box. Can you see if the bounding box covers the whole face? If bounding box is correct, can you share the original image so that i can test?
Ameer Hamza
2020년 4월 10일
I found a mistake in my code, which will misplace the pixelation region. Please try the updated code. Specifically, I changed these two lines
face = A(y:y+h, x:x+w, :); %<--- this
sz = size(face, [1 2]);
face = imresize(imresize(face, sz/20), sz, 'Method', 'nearest');
A(y:y+h, x:x+w, :) = face; %<--- this
Martin Schlachta
2020년 4월 10일
erik macejko
2021년 5월 8일
Can I use this code for more than one face? If no whats the solution for recognise and censure more faces in one picture?
Image Analyst
2021년 5월 8일
Yes, go ahead and try it.
erik macejko
2021년 5월 12일
Thanks, and Can I ask one more thing? What is this part of code doing?
face = A(y:y+h, x:x+w, :); %% this
sz = size(face, [1 2]); %% this
face = imresize(imresize(face, sz/20), sz, 'Method', 'nearest');
A(y:y+h, x:x+w, :) = face; %% and this
Thanks for your answers
Image Analyst
2021년 5월 13일
face = A(y:y+h, x:x+w, :); %% this crops a certain lateral ROI out of a color image.
sz = size(face, [1 2]); %% this returns the number of rows in the cropped face array as sz(1) and the number of columns as sz(2)
% Shrinks by factor of 20, then expand back to original size with replication
% to make it have a blocky appearance.
face = imresize(imresize(face, sz/20), sz, 'Method', 'nearest');
A(y:y+h, x:x+w, :) = face; %% and this puts the block image back into the original image at the original location.
카테고리
도움말 센터 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


