필터 지우기
필터 지우기

how can i blur an image background only

조회 수: 10 (최근 30일)
sanjit
sanjit 2023년 12월 10일
답변: DGM 2023년 12월 11일
suppose i want to blur an dog image backgroung..just background only not the dog..what code should i use for this?help please

답변 (1개)

DGM
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):

Community Treasure Hunt

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

Start Hunting!

Translated by