how to get boundary of a hand image???

3 views (last 30 days)
Rabia Butt
Rabia Butt on 19 Jun 2012
i am new to matlab. doing my project on hand geometry. i am stuck in finding the boundary of the image. infact I have found it but the resultant is an inverted image! please help me!
here is my code
I= imread('pre.jpg');
dim = size(BW);
col = round(dim(2)/2)-90;
row = find(BW(:,col), 1 );
boundary = bwtraceboundary(BW,[row, col],'N');
imshow(I)
K = plot(boundary(:,1),boundary(:,2),'k','LineWidth',3);

Answers (3)

Matt Kindig
Matt Kindig on 19 Jun 2012
Images in MATLAB are read in as row x column matrices, like any other matrix. Thus, the horizontal position of a given pixel is indicated by the 2nd dimension of a given position, while the vertical position is given by the 1st dimension of a given position. For example, given an image M that is 600 x 250, the pixel M(100,50) refers to the pixel that is 100 rows down (i.e. vertically) and 50 pixels right (i.e. horizontally).
By contrast, plots are commonly thought of in x-y coordinates, where the first coordinate is the horizontal (not vertical) position, and the second coordinate is the vertical position. Also, the origin for plots is (typically) at the lower left corner, while the origin for images is the upper left corner.
Thus, if you plot(boundary(:,2), boundary(:,1)), I believe the image should come out correctly. You should also search the Help for "axis ij" to understand how to change the axis orientation to accommodate either the image convention or the plot convention.

Image Analyst
Image Analyst on 19 Jun 2012
Use bwboundaries() instead. Then call "hold on" and plot right over your image. Upload your image if you want a demo.
  3 Comments
Rabia Butt
Rabia Butt on 19 Jun 2012
Edited: Walter Roberson on 13 Aug 2012
Here is my code
%%Read Image
a=imread('image1.jpg');
%%Show Image
imshow(a);
%%Gray-Scale Image
b= rgb2gray(a);
imshow(b)
%%Median Filtered Image
Y=medfilt2(b,[5 5]);
figure(2);
imshow(Y);
%%Bi-modal Histogram
imhist(Y)
%%BW Image
subplot(1,2,1), imshow(Y);
subplot(1,2,2), imshow(im2bw(Y))
%%Write Image
Z=im2bw(Y);
imshow(Z)
imwrite(Z,'pre.jpg','quality',10)
%%Morphological Opening
I = imread('pre.jpg');
se = strel('disk',10);
I_opened = imopen(I,se);
figure, imshow(I_opened,[])
imwrite(I,'open.jpg','quality',10)
%%Morphological Closing
originalBW = imread('open.jpg');
se = strel('disk',10);
closeBW = imclose(originalBW,se);
figure, imshow(closeBW)
imwrite(closeBW,'close.jpg','quality',10)
%%Image Boundary
J = imread('close.jpg');
BW = im2bw(I, graythresh(I));
[B,L] = bwboundaries(BW,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
end
%%Boundary Extraction
I= imread('close.jpg');
dim = size(BW);
col = round(dim(2)/2)-90;
row = find(BW(:,col), 1 );
boundary = bwtraceboundary(BW,[row, col],'N');
imshow(I)
plot(boundary(:,2),boundary(:,1),'k','LineWidth',3);
Image Analyst
Image Analyst on 14 Aug 2012
Nisha, regarding your comment to your "Answer":
Did you try ANDing the images?
intersectionImage = binaryImage1 & binaryImage2;
You can use poly2mask() if you need to turn polygon vertexes into binary images.

Sign in to comment.


Nisha Rajiv
Nisha Rajiv on 13 Aug 2012
I have used the same code and i have got the boundary of the image. now i need to make two image boundary to interact to check the interaction points. Since I am new to Matlab i have no idea how to proceed kindly guide me on this...
  2 Comments
Image Analyst
Image Analyst on 13 Aug 2012
I don't know what this means: "to interact to check the interaction points". What kind of interaction is taking place? Did you possibly mean intersect, instead of interact?
Nisha Rajiv
Nisha Rajiv on 13 Aug 2012
ya kind of...it is like i should make both the boundaries to touch each other and find out the number of points that are touching in both the boundaries. Like i have 2 polygons of irregular shape and now i extract the boundary and make them touch each other to find out their levels of interaction...Am i conveying correctly.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!