How to combine desired cropped image to another image?

8 vues (au cours des 30 derniers jours)
Drov
Drov le 23 Fév 2023
Commenté : Drov le 23 Fév 2023
Hello!
I want to crop only mask and wear on the face of image. I tried, but cropped mask image have other area (like white area). So, result like that in image3.
Can someone help me, please.
Thanks a lot!

Réponse acceptée

Luca Ferro
Luca Ferro le 23 Fév 2023
Modifié(e) : Luca Ferro le 23 Fév 2023
the easy solution is to find a mask image with a transparent background (format files as .png and .svg support it).
the medium solution is to find a tool (i.e adobe photoshop) to remove the background, save the image as .png and then use it.
the hard solution is to remove the background by image processing it in matlab. You may want to check out here some solutions: Search results: remove background - MATLAB Answers - MATLAB Central (mathworks.com)
  2 commentaires
Drov
Drov le 23 Fév 2023
Thanks a lot! I will try it.

Connectez-vous pour commenter.

Plus de réponses (3)

DGM
DGM le 23 Fév 2023
Modifié(e) : DGM le 23 Fév 2023
Here's a start.
In this example, the white region in the FG image is removed using a very crude one-sided S threshold. This is likely adequate, though refining the selection can be done by adding constraints (upper/lower limits on H and/or V). I removed the straps, since they wouldn't be in the right place anyway.
The scale and offset can be adjusted, but I've made no attempt to safeguard against the FG region being placed outside the BG extents.
I performed the FG masking prior to resizing in an attempt to maximize the smoothness of the mask edges. Note that the mask is cast numeric prior to resizing.
% read the images
FG = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1304830/madical%20mask.jpg');
BG = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1304835/backham.jpg');
% geometry parameters
fgscale = 0.24;
fgoffset = [65 145]; % [y x]
% generate FG mask
fghsv = rgb2hsv(FG);
FGa = fghsv(:,:,2) > 0.02;
% rescale FG and FGa
FG = imresize(FG,fgscale);
FGa = imresize(im2double(FGa),fgscale);
% get insertion location subscripts
szfg = size(FGa);
xrange = fgoffset(2):fgoffset(2)+szfg(2)-1;
yrange = fgoffset(1):fgoffset(1)+szfg(1)-1;
% extract BG region, compose, and replace
bgsample = im2double(BG(yrange,xrange,:));
bgsample = FGa.*im2double(FG) + (1-FGa).*bgsample;
BG(yrange,xrange,:) = im2uint8(bgsample); % assumes BG is uint8
imshow(BG);
Theeere we go.
  1 commentaire
Drov
Drov le 23 Fév 2023
Thanks a lot. It works. :)

Connectez-vous pour commenter.


Matt J
Matt J le 23 Fév 2023
You can adjust the AlphaData property of the image to make certain regions of the mask image transparent.
  1 commentaire
Drov
Drov le 23 Fév 2023
Thanks a lot. I will try it.

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 23 Fév 2023
  1 commentaire
Drov
Drov le 23 Fév 2023
Thanks a lot! It was pretty helped me. :)

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by