How to threshold an image when background and foreground color are similar to each other?

조회 수: 7(최근 30일)
Oguzhan Guvercin
Oguzhan Guvercin 2021년 12월 1일
댓글: Oguzhan Guvercin 2021년 12월 3일
Hi i would like to mask the background in this image so i have only the face of this baby as the output. But the background colors are very similar to the face skin color so when I'm applying thresholding im also losing the portion of the face or including the region that are unnecesary. How can I tackle this issue? What pre processing techniques should use? Or should take a different approach to the problem? What would you suggest?
Thanks in advance.

채택된 답변

yanqi liu
yanqi liu 2021년 12월 2일
clc; clear all; close all;
img = imread('');
% method 1
jmg = rgb2ycbcr(img);
s = jmg(:,:,2);
bw = ~imbinarize(s);
bw = bwareafilt(imopen(bw, strel('disk', round(size(bw,2)/5))), 1);
stats = regionprops(bw);
subplot(2, 2, 1); imshow(img);
subplot(2, 2, 2); imshow(s, []);
subplot(2, 2, 3); imshow(bw, []);
subplot(2, 2, 4); imshow(img, []);
hold on; rectangle('position', stats(1).BoundingBox, 'EdgeColor', 'g', 'LineWidth', 2)
% method 2
faceDetector = vision.CascadeObjectDetector();
faceDetector.ScaleFactor = 1.01;
bbox = step(faceDetector, img);
hold on; rectangle('position', bbox(1,:), 'EdgeColor', 'g', 'LineWidth', 2)
  댓글 수: 3
Oguzhan Guvercin
Oguzhan Guvercin 2021년 12월 3일
Thank you sincerely sir. I appreciate for your reply and time.

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

추가 답변(0개)




Community Treasure Hunt

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

Start Hunting!

Translated by