how can i blur an image background only
15 views (last 30 days)
Show older comments
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 Comments
Answers (1)
DGM
on 11 Dec 2023
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 Comments
See Also
Categories
Find more on Convert Image Type 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!

