How to combine desired cropped image to another image?
5 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
Luca Ferro
2023 年 2 月 23 日
編集済み: Luca Ferro
2023 年 2 月 23 日
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)
or here for some matlab exchange applets: Image Background Removal by User hand - File Exchange - MATLAB Central (mathworks.com)
2 件のコメント
DGM
2023 年 2 月 23 日
I agree. For something like this, grabbing a transparent PNG is going to be a lot simpler.
I don't think that there's an expectation that the composition needs to be good, and I don't doubt that there are many product images floating around that would be just fine.
その他の回答 (3 件)
DGM
2023 年 2 月 23 日
編集済み: DGM
2023 年 2 月 23 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!