これは四角形のバイナリ イメージです: http://www.google.com/search?tbm=isch&source=mog&hl=en&gl=us&client=ms-rim&tab=wi&q=rectangle%20binary&sa=N
左(xo)と右(x1)から座標を見つけて距離の長さを見つけ、座標の下(yo)と上(y1)から幅を見つけたいと思います。ここで : 長さ » 距離(X) = |X1-X0| 幅 » 距離 (Y) = |Y1-Y0|
よろしくお願いします
これは四角形のバイナリ イメージです: http://www.google.com/search?tbm=isch&source=mog&hl=en&gl=us&client=ms-rim&tab=wi&q=rectangle%20binary&sa=N
左(xo)と右(x1)から座標を見つけて距離の長さを見つけ、座標の下(yo)と上(y1)から幅を見つけたいと思います。ここで : 長さ » 距離(X) = |X1-X0| 幅 » 距離 (Y) = |Y1-Y0|
よろしくお願いします
For this input image you can simply do:
A = imread('art5.gif');
[y, x] = find(A==1);
my_length = max(x) - min(x) + 1
my_width = max(y) - min(y) + 1
This would give you:
my_length =
171
my_width =
89
Here since it is a logical gif, the above code would suffice. However, if the input image was in the RGB space, you would have needed:
A = im2bw(rgb2gray(imread('art5.gif')));
and if it was a grayscale image:
A = im2bw(imread('art5.gif'));
If you're using 'BoundingBox'
through the regionprops()
function:
A = imread('art5.gif');
s = regionprops(A, 'BoundingBox');
my_length = s.BoundingBox(3)
my_width = s.BoundingBox(4)
This would give you:
my_length =
171
my_width =
89