Which variable stores contour image ?

2 views (last 30 days)
close all;
clear all;
clc;
%Read the image, and capture the dimensions
img_orig = imread('C:\Users\Explorer\Documents\MATLAB\ASL_signs\A.jpg');
% % Create axes control.
% handleToAxes = axes();
% % Get the handle to the image in the axes.
% hImage = image(zeros(480,640,'uint8'));
% % Reset image magnification. Required if you ever displayed an image
% % in the axes that was not the same size as your webcam image.
% hold off;
% axis auto;
% axis on;
% % Enlarge figure to full screen.
% set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% annotation('textbox', [.2 .7 .3 .1],...
% 'String', 'Press Space Bar after placing your Hand in Bounding Box');
% % Turn on the live video.
% videoObject = videoinput('winvideo');
% preview(videoObject, hImage);
% hold on
% thisBB = [150 150 350 400]
% rect= rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],
'EdgeColor','g','LineWidth',2 )
% pause
% snap=getsnapshot(videoObject);
%
% stoppreview(videoObject)
% close all;
%
% cropped=imcrop(snap, thisBB)
% imshow(cropped)
%
%
% img_orig=cropped;
height = size(img_orig,1);
width = size(img_orig,2);
%Initialize the output images
out = img_orig;
bin = zeros(height,width);
%Convert the image from RGB to YCbCr
img_ycbcr = rgb2ycbcr(img_orig);
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
imshow(img_orig);
figure; imshow(out);
figure; imshow(bin);
%%Erode noise%%
imerode = imerode(bin, strel('square', 3));
figure,imshow(imerode);
%%Fill in holes to get fully connected skin regions%%
I = imfill(imerode, 'holes');
figure,imshow(I);
% imfill=~imfill;
% figure,imshow(imfill);
%
% Active Contour by chan-vase
m = zeros(size(I,1),size(I,2));
m(50:200,50:200) = 1;
seg = chenvese(I,m,1000,0.2,'chan'); % ability on gray image
% Built-in Mask
seg = chenvese(I,'medium',3000,0.02,'chan'); % ability on gray image
%-- End

Accepted Answer

Image Analyst
Image Analyst on 9 Feb 2014
First of all you can extract the biggest blob to get just the hand. I'm attaching a demo to help you with that.
Next, you can then use bwboundaries() if you want all the coordinates of the hand outer perimeter exactly, or you can use activecontour, a built-in function, instead of that file exchange submission. I have a demo for that (on my other computer), if you're interested.
If you want to build up an image from the coordinates given to you by bwboundaries you can easily do that with a for loop:
contourImage = false(size(bin));
for k = 1 : length(xCoordinates)
row = int32(yCoordinates(k));
column = int32(xCoordinates(k));
contourImage(row, column) = true;
end

More Answers (1)

Walter Roberson
Walter Roberson on 7 Feb 2014
None of the code you show produces that plot. The plot is likely put up within the showphi() routine that you did not provide source for. The key inputs to that routine appear to be I and phi0 within the chenverse routine, provided that the 'chan' or 'vector' options are given to it (you provide 'chan'). The phi0 variable is then returned from chenvese, where it becomes your variable "seg"
  3 Comments
Explorer
Explorer on 10 Feb 2014
Edited: Explorer on 10 Feb 2014
Thank you for answering Walter Roberson.
You answer is also accepted.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by