Pixeling only detected face
Ältere Kommentare anzeigen
% 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.
Akzeptierte Antwort
Weitere Antworten (1)
Ameer Hamza
am 10 Apr. 2020
Bearbeitet: Ameer Hamza
am 10 Apr. 2020
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 Kommentare
Martin Schlachta
am 10 Apr. 2020
Ameer Hamza
am 10 Apr. 2020
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
am 10 Apr. 2020
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
am 10 Apr. 2020
erik macejko
am 8 Mai 2021
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
am 8 Mai 2021
Yes, go ahead and try it.
erik macejko
am 12 Mai 2021
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
am 13 Mai 2021
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.
Kategorien
Mehr zu Computer Vision with Simulink finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


