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).