Asked by Milad
on 1 Apr 2014

Hi

I have a binary image which I have extracted the perimeter with bwperim() function. Now that I have the perimeter image I am trying to extract the coordinates of pixels in this perimeter.Here are the images:

The white perimeter illustrated in the second image is where I want to find the coordinates. Any Suggestions is appreciated.

Thanks

Answer by Nitin
on 1 Apr 2014

Accepted Answer

Assuming your image is a binary one:

[a,b]= find(I==1); % get the coordinates

Milad
on 1 Apr 2014

Thanks Nitin for the answer. It worked.

Dishant Arora
on 1 Apr 2014

If it works accept the answer.

Sign in to comment.

Answer by Dishant Arora
on 1 Apr 2014

If you have a single blob the above answer would suffice but in case you have multiple objects use bwboundaries. It gives you the coordinates of boundary pixels.

doc bwboundaries

Milad
on 1 Apr 2014

Thanks Dishant. At this time I am dealing with only one region(or blob as you called it:actually this is a converted aggregate image) per image but I might need to work with bwboundaries() too, as I may deal with multi-regions in the future. For this problem I couldn't get the matrix of pixel positions by his function. I used this code:

[x,y] = bwboundaries(bw,'noholes');

where,bw is the input image(second image illustrated in the main Question).which returns this result:

[471x2 double] [360x480 double]

in which the right one is the resolution of the input picture and I guess "double" is referred to it's class. I am not sure about the left one because it does not have the same dimension as the matrix derived from find() function. Any ideas?

Dishant Arora
on 1 Apr 2014

Image Analyst
on 1 Apr 2014

Sign in to comment.

Answer by Arriana Nwodu
on 13 Aug 2018

So which code is correct? I tried all the ways listed and it didn't work

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## mahesh pawar (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/123943-how-can-i-find-pixel-coordinates-of-a-perimeter-in-a-binary-image#comment_433801

## Image Analyst (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/123943-how-can-i-find-pixel-coordinates-of-a-perimeter-in-a-binary-image#comment_433823

## Cam S (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/123943-how-can-i-find-pixel-coordinates-of-a-perimeter-in-a-binary-image#comment_725789

Sign in to comment.