% Load the facial image
I = imread('face_image.jpg'); % جایگزینی نام فایل با نام تصویر واقعی
% Convert to grayscale if necessary
if size(I, 3) == 3
I_gray = rgb2gray(I);
else
I_gray = I;
end
% Enhance contrast to better visualize features
I_enhanced = imadjust(I_gray);
% Detect eyes region using a pre-trained cascade object detector
eyeDetector = vision.CascadeObjectDetector('EyePairBig');
bbox = step(eyeDetector, I_enhanced);
% Display the detected eye region
figure;
imshow(I_enhanced);
hold on;
for i = 1:size(bbox, 1)
rectangle('Position', bbox(i, :), 'LineWidth', 2, 'EdgeColor', 'b');
end
title('Detected Eye Region');
% Simulate changing the eye region (e.g., enlarging eyes)
scaleFactor = 1.1; % Example: Enlarging the eyes by 10%
resizedEyes = imresize(imcrop(I_enhanced, bbox(1, :)), scaleFactor);
% Place the resized eyes back into the image
eyePosition = round(bbox(1, 1:2) - [(size(resizedEyes, 2) - bbox(1, 3))/2, (size(resizedEyes, 1) - bbox(1, 4))/2]);
I_modified = I_enhanced;
I_modified(eyePosition(2):(eyePosition(2) + size(resizedEyes, 1) - 1), ...
eyePosition(1):(eyePosition(1) + size(resizedEyes, 2) - 1)) = resizedEyes;
% Display the original and modified images
figure;
subplot(1, 2, 1), imshow(I_enhanced), title('Original Eyes');
subplot(1, 2, 2), imshow(I_modified), title('Simulated Eyes after Surgery');