how to connect coordinate points?

1 visualizzazione (ultimi 30 giorni)
Sayak
Sayak il 4 Ott 2012
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);

Risposta accettata

Matt Kindig
Matt Kindig il 4 Ott 2012
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 Commenti
Sayak
Sayak il 5 Ott 2012
Modificato: Sayak il 5 Ott 2012
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 il 6 Ott 2012
No, this is definitely NOT the correct approach. It will absolutely fail for many images. See my latest comment.

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 4 Ott 2012
Modificato: Image Analyst il 5 Ott 2012
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 Commenti
Sayak
Sayak il 17 Ott 2012
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 il 17 Ott 2012
Research the literature for people who have done similar things.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by