how can i blur an image background only
10 次查看(过去 30 天)
显示 更早的评论
suppose i want to blur an dog image backgroung..just background only not the dog..what code should i use for this?help please
0 个评论
回答(1 个)
DGM
2023-12-11
Using basic tools:
% an image (RGB, uint8)
inpict = imread('peppers.png');
imshow(inpict,'border','tight')
% a mask which selects the BG (I, uint8)
% this happens to be antialiased, but it's not necessary
mask = imread('redpepmask.png');
mask = imcomplement(mask);
imshow(mask,'border','tight')
% blur a copy
blurred = imgaussfilt(inpict,5);
% compose the output
mask = im2double(mask);
outpict = im2double(blurred).*mask + im2double(inpict).*(1-mask);
outpict = im2uint8(outpict);
% show it
imshow(outpict,'border','tight')
See also:
Local blurring meta-answer:
An example of using roifilt2() on an RGB image can be found here:
An example of doing blurring (hard and soft masks) using basic composition methods and basic MATLAB/IPT tools can be found here:
An example of doing soft-masked blurring using purpose-built composition tools can be found here (see the last face-blurring example):
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!