auto detection of an image bacjground and blur it
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Sulaymon Eshkabilov
2023-12-20
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 个评论
另请参阅
类别
在 Help Center 和 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!