1

I have a binary image which contains BLOBs with distinct size.
Input Image
enter image description here
I can calculate the area using nnz(), which calculated the number of white pixels.

% my code
C     = imread( 'InputImage' );
C     = im2bw( C );
carea = nnz( C );
disp( carea );
%

But I want to know their value in centimeter or millimeter.

Is it possible?

How?

Community
  • 1
  • 1
rezwan
  • 39
  • 1
  • 4
  • Simply, calibrate the input against a reference-sized grid & use such px-size direct conversion to [mm^2]. – user3666197 May 08 '17 at 18:49
  • sorry. can't understand. is there any code? or should i measure it manually? @user3666197 – rezwan May 08 '17 at 18:58
  • 1
    you need to know how big a pixel in the object plane is. the simplest way to get that size is to capture something of known size and then count the pixels to get a conversion factor... – Piglet May 08 '17 at 19:04

2 Answers2

1

There is a possible way to estimate/calculate the size of an object in image.

If digital image itself is the only information you have, you can't know. Otherwise, you need to get "spatial calibration factor", shortly, you image an object with same distance to camera with known size and get the pixel per centimeters, a long answer can be found:

https://www.mathworks.com/matlabcentral/answers/56087-how-can-i-find-the-spatial-calibration-factor

Normally, such task would require a segmentation and localization of the object, but, I assume, in your problem image is always binary and there is only one white object. Now, you also need to know, the precision of your measurement will be bounded by the discretization error. For example, if you take a photo of 10.49 meters to 10.49 meters square with regard to camera position, object's photo, with very low resolution(e.g 100 pixels, 10 pixels), up to 0.5 meter error will prevail, and you might simply miss 49 centimeters in each 2 dimensions and with a binary digital image, there is not much you can do to get rid off this error.

Semih Korkmaz
  • 1,125
  • 13
  • 26
1

I don't know what the source of the image is, but PNG files have header fields that encode the resolution. You can use the function imfinfo to get this information. For your image, this is what I get:

>> info = imfinfo('czYGP.png')
info = 
  struct with fields:

                  Filename: 'czYGP.png'
               FileModDate: '08-May-2017 15:00:13'
                  FileSize: 1275
                    Format: 'png'
             FormatVersion: []
                     Width: 266
                    Height: 280
                  BitDepth: 24
                 ColorType: 'truecolor'
           FormatSignature: [137 80 78 71 13 10 26 10]
                  Colormap: []
                 Histogram: []
             InterlaceType: 'none'
              Transparency: 'none'
    SimpleTransparencyData: []
           BackgroundColor: []
           RenderingIntent: 'perceptual'
            Chromaticities: [0.3127 0.3290 0.6400 0.3300 0.3000 0.6000 0.1500 0.0600]
                     Gamma: 0.4545
               XResolution: 3779
               YResolution: 3779
            ResolutionUnit: 'meter'
                   XOffset: []
                   YOffset: []
                OffsetUnit: []
           SignificantBits: []
              ImageModTime: []
                     Title: []
                    Author: []
               Description: []
                 Copyright: []
              CreationTime: []
                  Software: []
                Disclaimer: []
                   Warning: []
                    Source: []
                   Comment: []
                 OtherText: []

The interesting fields here are 'XResolution' and 'YResolution', both in pixels per 'ResolutionUnit', which is 'meter'. Using this info, we can compute the pixel size for your image:

pixelSize = 100./[info.XResolution info.YResolution];   % In cm/pixel
pixelSize = 1000./[info.XResolution info.YResolution];  % In mm/pixel

Now, all you have to do is multiply any area measurements you get by the pixel area, like so:

carea = nnz(C)*prod(pixelSize);

NOTE: Of course, this all assumes that this header information was set to the proper values, and not just default values or arbitrarily set or modified at any point. This is why the source of the image matters, and if it's trustworthy (like if it's from some medical imaging device or software).

gnovice
  • 125,304
  • 15
  • 256
  • 359