필터 지우기
필터 지우기

auto detection of an image bacjground and blur it

조회 수: 2 (최근 30일)
sanjit
sanjit 2023년 12월 20일
답변: Sulaymon Eshkabilov 2023년 12월 20일
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.

답변 (1개)

Sulaymon Eshkabilov
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');

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by