how to connect coordinate points?

조회 수: 3 (최근 30일)
Sayak
Sayak 2012년 10월 4일
I have used bwlabel to label the connected components of a picture.Then I have used find() to have the coordinates for the pixels in object 1 and saved it in [r c].
Now is there any way to use those co-ordinate and draw them again to reconstruct the object?
My code is something like that::
img = imread('global1.jpg');
b_img = im2bw(img);
[m,n] = bwlabel(b_img,4);
[r c] = find(m==1);

채택된 답변

Matt Kindig
Matt Kindig 2012년 10월 4일
Hi Sayak,
I'm a little bit unclear on what you are trying to do, but I think you want to use bwboundaries. That will give you the coordinates on the border of the image, which you can then use to reconstruct the object.
doc bwboundaries
doc bwtraceboundary
  댓글 수: 4
Sayak
Sayak 2012년 10월 5일
편집: Sayak 2012년 10월 5일
Yes I have done that. Now to distinguish male and female I have used the following approach.
1) Taking an array full of 0's, having a size equal to the original image and named this array as 'mask'.
2) Storing the values of Male (by doing male = find(L==1);) in [r c].
3) For each values of male array, I have changed the value of the array mask to 1. Thus it will only show the pixel positions of male in the mask.
4)Typecast mask to logical/uint8 and do a imshow() thus only to show the male-part of the original image.
Problem : As the main image is of 90 x 91 and the mask is also 90 x 91. But the male array is of 6021 x 2. So whenever I am checking the values of mask and male it produces 'array out of bound exception'.
I do not know how to get rid of that problem. What should I do?
My code so far::
img = imread('C:\Users\Sayak\Documents\MATLAB\mat_pic\global1.jpg');
%img = imresize(img,0.5);
b_img = im2bw(img);
[glo_r,glo_c,glo_p] = size(b_img);
%edge(b_img);
for i = 1 : glo_r
for j = 1 : glo_c
mask(i,j) = 0;
end
end
[m,n] = bwlabeln(b_img,4);
[r1 c1] = find(m==1);
rc = [r1 c1];
for i = 1 : glo_r
for j = 1 : glo_c
if(mask(i,j) ~= rc(i,j))
mask(i,j) = 1;
end
end
end
imshow(logical(mask)); % is it correct approach ?
Image Analyst
Image Analyst 2012년 10월 6일
No, this is definitely NOT the correct approach. It will absolutely fail for many images. See my latest comment.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2012년 10월 4일
편집: Image Analyst 2012년 10월 5일
The usual Mathworks-recommended way is to use ismember():
keeperBlobsImage = ismember(labeledImage, blobNumberToKeep);
where blobNumberToKeep can be either a single number of a vector of numbers that you want to keep. See my BlobsDemo for a demo http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 - I extract out two types of coins from the standard MATLAB demo image.
  댓글 수: 22
Sayak
Sayak 2012년 10월 17일
I saw it. But it is totally different from what my picture is. Using watershed (following Steve's demo) does not seem to be working on my picture. In this context what should I do?
Image Analyst
Image Analyst 2012년 10월 17일
Research the literature for people who have done similar things.

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

Community Treasure Hunt

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

Start Hunting!

Translated by