background removal from image

조회 수: 25 (최근 30일)
Malini Bakthavatchalam
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
Malini Bakthavatchalam
Malini Bakthavatchalam 2020년 5월 27일
Actually my question is I have used color thresholding method to remove background from the image, i want to calculate the histogram only from the facepixels and not from background... but when you look at the final image the calculation is including background. I dont want the analysis with background
Malini Bakthavatchalam
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개)

Subhadeep Koley
Subhadeep Koley 2020년 5월 27일
Malini, here is a demo script for "...histogram of the person's face not the background..."
close all
clc
img = imread('dkloriginalimg.jpg');
% Create a binary image mask
grayImg = rgb2gray(img);
maskBW = grayImg(:, :) ~= 0;
maskBw = imfill(maskBW, 'holes');
% Display original image
subplot(1, 3, 1)
imshow(img, [])
title('Original Image')
% Display the mask
subplot(1, 3, 2)
imshow(maskBw)
title('Binary mask')
% Calculate the histogram
pixelsWithinMask = img(maskBw);
[pixCnt, lavels] = imhist(pixelsWithinMask);
subplot(1, 3, 3)
bar(lavels, pixCnt)
title('Histogram of the masked image')
axis square
grid on
Hope this helps!
  댓글 수: 4
Malini Bakthavatchalam
Malini Bakthavatchalam 2020년 5월 27일
Is there any hope for my issue?
Subhadeep Koley
Subhadeep Koley 2020년 5월 28일
@ Malini Bakthavatchalam Refer the code below,
close all; clear; clc;
img = imread('dkloriginalimg.jpg');
% Create a binary image mask
grayImg = rgb2gray(img);
maskBW = grayImg(:, :) ~= 0;
maskBW = imfill(maskBW, 'holes');
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
imhist(img(maskBW))
title('original hist')
figure
imhist(K(maskBW))
title('lower rectified hist')
ylim([0 10000])
figure
imhist(P(maskBW))
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)
imhist(K(maskBW))
title('lower rectified hist')
subplot(2, 3, 5)
imhist(img(maskBW))
title('original hist')
subplot(2, 3, 6)
imhist(P(maskBW))
title('upper rectified hist')
Hope this helps!

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

카테고리

Help CenterFile Exchange에서 Get Started with Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by