Borrar filtros
Borrar filtros

how can i blur an image background only

10 visualizaciones (últimos 30 días)
sanjit
sanjit el 10 de Dic. de 2023
Respondida: DGM el 11 de Dic. de 2023
suppose i want to blur an dog image backgroung..just background only not the dog..what code should i use for this?help please

Respuestas (1)

DGM
DGM el 11 de Dic. de 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):

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by