I want to know find height and width of binary image and angle

5 次查看(过去 30 天)
Sample this image output Height 180 Width 145 and find degrees from center of picture 4 angle

回答(1 个)

Guillaume
Guillaume 2017-2-10
Your question is really not clear, at a guess you want the height width and general angle of the white figure in your image. All can be simply obtained with regionprops.
But first of all, JPEG is completely the wrong format for storing binary images:
>>img = imread('bw00018.jpg'); %read image
>>intensities = unique(img(:))' %get list of all intensity values in the image:
intensities =
1×74 uint8 row vector
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
22 23 24 25 26 27 28 29 30 31 34 35 36 37 39 216 217 220 221 222 224 225
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
248 249 250 251 252 253 254 255
Your image is no longer binary due to the way standard jpeg compression works. Use a non-lossy image format such as PNG.
Anyway,
bw = img > 127; %convert to binary image using arbitrary threshold
props = regionprops(bw, 'all');
shapeheight = props.BoundingBox(4)
shapewidth = props.BoundingBox(3)
shapeanglefromhorz = props.Orientation;
Orientation is the angle of the ellipse that best fit your shape.
  5 个评论

请先登录,再进行评论。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by