Hand Segmentation Based on Thresholding Coding \\ image processing

my project is about to segment the hand from the background, i try this code it works well with some image only ! but the image with complex background does not work correctly this is the code
clc;
workspace
fontSize = 20;
folder = '/Users/lolo/Desktop';
baseFileName = 'A.png';
% Get the full filename, with path prepended.
fullFileName = fullfile('/Users/Roa/Desktop', 'A.png');
currentimg=imread(fullFileName);
%capture the image of interest%
subplot(2,2,1);
imshow(currentimg);
title('Original Image', 'FontSize', fontSize);
%Read the image, and capture the dimensions
VidImage = currentimg;
height = size(VidImage,1);
width = size(VidImage,2);
%Initialize the output images
out = VidImage;
bin = zeros(height,width);
%Convert the image from RGB to YCbCr
img_ycbcr = rgb2ycbcr(VidImage);
Cb = img_ycbcr(:,:,2);
Cr = img_ycbcr(:,:,3);
%Detect Skin
[r,c,v] = find(Cb>=77 & Cb<=127 & Cr>=133 & Cr<=173);
numind = size(r,1);
%Mark Skin Pixels
for i=1:numind
out(r(i),c(i),:) = [0 0 255];
bin(r(i),c(i)) = 1;
end
binaryImage= imbinarize(bin,graythresh(bin));
% binaryImage=~binaryImage;
subplot(2,2,2);
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize);
B = bwboundaries(binaryImage);
% imshow(binaryImage)
binaryImage = imfill(binaryImage, 'holes');
% Remove tiny regions.
binaryImage = bwareaopen(binaryImage, 5000);
subplot(2,2,3);
imshow(binaryImage);
title('Second Binary Image', 'FontSize', fontSize);
%---------------------------------------------------------------------------
% Extract the largest area using ImageAnalyst's custom function ExtractNLargestBlobs().
biggestBlob = ExtractNLargestBlobs(binaryImage, 1);
% Display the image.
subplot(2,2, 4);
imshow(biggestBlob);
title('Final Image', 'FontSize', fontSize);
%--------------------------------------------------------------------------
[labeledImage, numberOfBlobs] = bwlabel(biggestBlob, 8);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'BoundingBox','Area');
allBlobAreas = [blobMeasurements.Area];
% Display the original gray scale image.
subplot(2,2,1);
% Loop through all blobs, putting up Bounding Box.
hold on; % Prevent boxes from blowing away the image and prior boxes.
for k = 1 : numberOfBlobs
boundingBox = blobMeasurements(k).BoundingBox; % Get box.
x1 = boundingBox(1);
y1 = boundingBox(2);
x2 = x1 + boundingBox(3) - 1;
y2 = y1 + boundingBox(4) - 1;
verticesX = [x1 x2 x2 x1 x1];
verticesY = [y1 y1 y2 y2 y1];
plot(verticesX, verticesY, 'r-', 'LineWidth', 2);
end
uiwait(msgbox('Done with demo'));

댓글 수: 2

Guillaume
Guillaume 2017년 5월 1일
편집: Guillaume 2017년 5월 1일
Your question is essentially:
Here is some code. I'm not going to explain how it works and what it does, but can somebody spends the time to understand it, then improve it so that it works on some unspecified set of images that I'm not going to show.
Image processing of completely arbitrary images is very hard. If you don't restrict what is allowed in the image you're never going to have 100% working code.
Really? I didn't even see a question there. It looks more like an announcement to me.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2017년 5월 1일

댓글:

2017년 5월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by