How to calculate area in a binary image?
Show older comments
I have two questions to ask:
1) How to calculate area at the white region in binary image?
2) How to convert the answer of area unit that get from matlab into cm^2 or mm^2 (SI UNIT)?
here I attach the original image and binary image (this image is marine growth on the fiberglass plate)

Accepted Answer
More Answers (1)
Image Analyst
on 22 Sep 2020
0 votes
See my attached spatial calibration demo.
12 Comments
Asmalina Mohamed Saat
on 1 Oct 2020
Image Analyst
on 3 Oct 2020
inputdlg() returns a cell array called answer. To get the contents of the first edit field you need to use answer{1}, and answer{2} is the contents of the second edit field. They will be strings so you need to convert them to numbers with str2double() if you need them to be a number.
See the FAQ for a good intuitive explanation of cell arrays and matrices and when to use braces, parentheses, and brackets.
Asmalina Mohamed Saat
on 6 Oct 2020
Image Analyst
on 7 Oct 2020
- Yes
- No. distanceInPixels is the length of the line you drew, in pixels. Not sure what you mean by the "length" of the 2-D image, but distanceInPixels is not the same as the height in rows (lines) of the image, or of the width (columns) of the image.
- area will be the area in pixels.
Asmalina Mohamed Saat
on 7 Oct 2020
Image Analyst
on 7 Oct 2020
Not quite. If you drew a line along your known reference object that was 165 pixels long and that represents 10 cm, then the spatial calibration factor is 10/165 = 0.0606060606060606 (not 0.022).
Now if you drew another line that was 462 pixels long, it would be 462 * 0.0606060606060606 = 28 cm long (not 10 cm)
If you have a region that is 15336 pixels in area, then the area would be 15336 * 0.0606060606060606^2 = 56.33 square cm, not 7.422 square cm.
Asmalina Mohamed Saat
on 8 Oct 2020
Edited: Asmalina Mohamed Saat
on 8 Oct 2020
Image Analyst
on 8 Oct 2020
Not sure I understand. They're the same thing. You said "also", so how are you getting two different things? You basically have one factor that is how many real world units there are per pixel. For linear distances you multiply pixels by that. For areas you multiply by that squared. There is only one factor, not two, so there is no "also".
Asmalina Mohamed Saat
on 9 Oct 2020
Image Analyst
on 9 Oct 2020
Yes the units will now be calibrated so the units will now be square cm instead of pixels.
Asmalina Mohamed Saat
on 13 Oct 2020
Image Analyst
on 13 Oct 2020
The number of white pixels is, of course, unitless. It's just simply a count, like 235 or 14983 or whatever. It can have an area in pixels or square cm but the count is obviously just a number and has no units at all.
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!