background removal from image

조회 수: 36 (최근 30일)
Malini Bakthavatchalam . 2020년 5월 26일
댓글: Malini Bakthavatchalam . 2020년 5월 28일
Hi , I am working on a project in color illusion. And I want to remove the background from the image, the image is a person's face with white bakground, I used matlab function color thresholding to remove the background, after that I convertd the image color space to DKL space, then I started with my project, but still in my analysis the whole image is getting calculated . I want to work with the histogram of the person's face not the background. I am attaching my whole code here.. kindly help me.
2. since I am new to matlab, I learnt my codes in bits and pieces using tutorial, I want to know how to connect all my pieces together. Like starting from background removal, then using the background removed image to convert in different color space. finally using this color space image in calculating my histograms and creating illusion. so, I have written my codes in parts ... that does all this function but not together in one script. I am stuck with how to combine all these.
Kindl guide me through this
댓글 수: 6이전 댓글 5개 표시이전 댓글 5개 숨기기
Malini Bakthavatchalam 2020년 5월 28일
@Image Analyst : May be i can put my question in a this way like, how do i remove the foreground(person's face) from the background, then do my further analysis only with the foreground image ?.

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

답변 (1개)

Malini, here is a demo script for "...histogram of the person's face not the background..."
close all
clc
% Create a binary image mask
grayImg = rgb2gray(img);
maskBW = grayImg(:, :) ~= 0;
% Display original image
subplot(1, 3, 1)
imshow(img, [])
title('Original Image')
subplot(1, 3, 2)
% Calculate the histogram
subplot(1, 3, 3)
bar(lavels, pixCnt)
axis square
grid on
Hope this helps!
댓글 수: 4이전 댓글 3개 표시이전 댓글 3개 숨기기
@ Malini Bakthavatchalam Refer the code below,
close all; clear; clc;
% Create a binary image mask
grayImg = rgb2gray(img);
maskBW = grayImg(:, :) ~= 0;
K_median_cal = reshape(img, [], 1);
total_median = median(K_median_cal);
% I have commnted these lines as K and P values are being overwritten
% below in the for loop. Uncomment if you wish so
% K(G<total_median) = G(G<total_median);
% P(G>total_median) = G(G>total_median);
K = uint8(double(total_median) .* ones(size(img)));
P = uint8(double(total_median) .* ones(size(img)));
for i = 1:length(img(:, 1))
for j = 1:length(img(1, :))
if img(i, j) < total_median
K(i, j) = img(i, j);
else
P(i, j) = img(i, j);
end
end
end
% Visualization
figure
imshow(img)
title('original DKL img')
figure
imshow(K)
title('lower rectified')
figure
imshow(P)
title('upper rectified')
figure
title('original hist')
figure
title('lower rectified hist')
ylim([0 10000])
figure
title('upper rectified hist')
ylim([0 10000])
figure
subplot(2, 3, 1)
imshow(K)
title('lower rectified')
subplot(2, 3, 2)
imshow(img)
title('original DKL img')
subplot(2, 3, 3)
imshow(P)
title('upper rectified')
subplot(2, 3, 4)
title('lower rectified hist')
subplot(2, 3, 5)
title('original hist')
subplot(2, 3, 6)
title('upper rectified hist')
Hope this helps!

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

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by