How to extract the hand out of the background? (homework assignment)

조회 수: 2 (최근 30일)
Tu Nguyen
Tu Nguyen 2022년 3월 12일
편집: DGM 2022년 3월 12일
Dear all, I want 'my output' image like exactly 'ouput' image. I followed step by step on the intrunction posted here.
Can anyone help me please?
clc;
close all;
clear all;
I1 = imread('hands.png');
I2 = imread('balcony.png');
gr = im2gray(I1);
threshold_value = graythresh(gr);
bw = im2bw(gr);
binary = bw<threshold_value;
binary_I = imfill(binary,'holes');
imshow(binary_I);
mask = I1;
mask(~bw) = 0;
ig = im2gray(mask);
output = bitand(ig,I2);
imshow(output);
  댓글 수: 2
Image Analyst
Image Analyst 2022년 3월 12일
You forgot to post 'hands.jpg' and 'balcony.jpg'. Please do so after reading this:
Tu Nguyen
Tu Nguyen 2022년 3월 12일
Yes sir, I already read and upload the images. If you know, please help me fix the code

댓글을 달려면 로그인하십시오.

채택된 답변

DGM
DGM 2022년 3월 12일
편집: DGM 2022년 3월 12일
If you're trying to create the composite image:
FG = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/924699/hands.png');
BG = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/924694/balcony.png');
mask = FG<210; % basic thresholding
outpict = uint8(double(FG).*mask + double(BG).*(~mask)); % compose image
imshow(outpict)
Alternatively, you can go to extra lengths to improve the masking:
mask = FG<210; % same thresholding
mask = imerode(mask,ones(7)); % shrink mask to remove edge banding
mask = imgaussfilt(double(mask),1.5); % feather mask back toward original edges
outpict = uint8(double(FG).*mask + double(BG).*(1-mask)); % compose
imshow(outpict)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by