why does bwperim make the border WHITE?!!

I want to use bwperim to calculate the perimeter of an object, but I got a strange thing!
I use bwperim in two different states: first to the original binary image and second to its inverse, i.e.,:
%%binaryImage
perim1 = bwperim (binaryImage);
perim2 = bwperim (~binaryImage);
The strange thing is that the first one (perim1) gives an image that is almost black (except the detected boundaries, of course), but:
Exactly, the borders of the whole image, I mean the FIRST row and column and the LAST row and column are white! I mean it has given the value of 1 to the pixels of the image border! Why?!!
For the second one (perim2), this is not the case and it is correct as the original image.
The binary image:
perim1 (with white border):
perim2:
Thanks so much!
Steven

6 件のコメント

Walter Roberson
Walter Roberson 2013 年 12 月 25 日
Could you post your binaryImage and your perim1 and perim2 ?
Walter Roberson
Walter Roberson 2013 年 12 月 25 日
I cannot tell for sure, but it looks to me as if the original might have a single-row outline of 0's all around it.
Steven
Steven 2013 年 12 月 25 日
How can I avoid or correct it?
Walter Roberson
Walter Roberson 2013 年 12 月 25 日
How did you create the binary image? What image did you start with and how did you process it?
Walter Roberson
Walter Roberson 2013 年 12 月 25 日
but be careful about the possibility that some of your image touches the border.
Steven
Steven 2013 年 12 月 25 日
for creating binary, I used:
binaryimage = im2bw(gray_scale_image,graythresh(gray_scale_image)

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2013 年 12 月 25 日

0 投票

I don't think perim1 should have the edges of the image as white. Can you post the binary image so I can check it out?

4 件のコメント

Steven
Steven 2013 年 12 月 25 日
編集済み: Steven 2013 年 12 月 25 日
Thanks.
I posted them above.
Thanks
Steven
Image Analyst
Image Analyst 2013 年 12 月 25 日
Well, the binary image is white at the edges. It assumes that that is the end (outer perimeter) of your object so it sets the edge pixels white. So it makes sense, don't you think? If you're going to assume that your object continues as white outside the boundaries of the image then you should erase the white lines after calling bwperim():
perim1(1,:) = false;
perim1(1,end) = false;
perim1(:,1) = false;
perim1(:,end) = false;
Steven
Steven 2013 年 12 月 25 日
Thanks.
How about using imclearborder? It does the same right?
Thanks.
Steven
Walter Roberson
Walter Roberson 2013 年 12 月 25 日
Erasing the borders yourself is safer if you might possibly have an object touching the edge. If you know you will not, then imclearborder() is more convenient.

サインインしてコメントする。

その他の回答 (0 件)

タグ

質問済み:

2013 年 12 月 25 日

編集済み:

2014 年 1 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by