auto detection of an image bacjground and blur it
2 views (last 30 days)
Show older comments
give a matlab code for this image that can focous the human then automitically detec this image background and then blur the background..this should work like potrait mode.
0 Comments
Answers (1)
Sulaymon Eshkabilov
on 20 Dec 2023
Here is one code that requires yolov2ObjectDetector() from YOLO model and does the job partially.
% Read your image:
O_Image = imread('H_image.jpeg');
% Load pre-trained YOLO model for object detection
yolonet = yolov2ObjectDetector();
% Detect objects in the image using YOLO
[bbox, score, label] = detect(yolonet, O_Image);
% Create a binary mask for humans
binaryMask = false(size(O_Image, 1), size(O_Image, 2));
for jj = 1:size(bbox, 1)
binaryMask(bbox(jj,2):bbox(i,2)+bbox(jj,4)-1, bbox(jj,1):bbox(jj,1)+bbox(jj,3)-1) = true;
end
% Convert binary mask to double
b_Mask = double(binaryMask);
% Blur the background using a Gaussian filter
blur_Background = imgaussfilt(O_Image, 10);
% Combine blurred background with original foreground (humans)
finalImage = double(originalImage) .* repmat(b_Mask, [1, 1, size(O_Image, 3)]) + ...
double(blur_Background) .* repmat(1 - b_Mask, [1, 1, size(O_Image, 3)]);
% The final image in uint8 format
F_Image = uint8(finalImage);
% Display and compare the obtained image
figure
imshow(O_Image);
title('Original Image');
figure
imshow(F_Image);
title('Blurred Background with Detected Humans');
0 Comments
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!