Clear Filters
Clear Filters

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

5 views (last 30 days)
Sample this image output Height 180 Width 145 and find degrees from center of picture 4 angle

Answers (1)

Guillaume
Guillaume on 10 Feb 2017
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 Comments
Image Analyst
Image Analyst on 13 Feb 2017
Edited: Image Analyst on 13 Feb 2017
dx = xRed - xCentroid;
dy = yRed - yCentroid;
angle = atan2d(dy, dx);

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!