% Detect facial features using a pre-trained detector
faceDetector = vision.CascadeObjectDetector('FrontalFaceCART');
bbox = step(faceDetector, I_enhanced);
% Display detected face
figure;
imshow(I_enhanced);
hold on;
for i = 1:size(bbox, 1)
rectangle('Position', bbox(i, :), 'LineWidth', 2, 'EdgeColor', 'r');
end
title('Detected Face');
% Crop the face region
faceImage = imcrop(I_enhanced, bbox(1, :));
% Further feature detection (eyes, nose, mouth)
eyeDetector = vision.CascadeObjectDetector('EyePairBig');
eyeBbox = step(eyeDetector, faceImage);
noseDetector = vision.CascadeObjectDetector('Nose');
noseBbox = step(noseDetector, faceImage);
mouthDetector = vision.CascadeObjectDetector('Mouth');
mouthBbox = step(mouthDetector, faceImage);
% Display detected features
figure;
imshow(faceImage);
hold on;
for i = 1:size(eyeBbox, 1)
rectangle('Position', eyeBbox(i, :), 'LineWidth', 2, 'EdgeColor', 'g');
end
for i = 1:size(noseBbox, 1)
rectangle('Position', noseBbox(i, :), 'LineWidth', 2, 'EdgeColor', 'b');
end
for i = 1:size(mouthBbox, 1)
rectangle('Position', mouthBbox(i, :), 'LineWidth', 2, 'EdgeColor', 'y');
end
title('Detected Facial Features');