you can write code for simple formula https://www.unitconverters.net/typography/pixel-x-to-inch.htm
also look on some topics on mathworks https://www.mathworks.com/matlabcentral/answers/138153-how-to-convert-pixel-to-cm-or-inch-i-want-to-know-1-pixel-equal-mm-or-cm-inch https://in.mathworks.com/matlabcentral/answers/121842-pixels-to-inch-conversion
It depends on your image resolution. if the image´s pixel density is 96 dpi, it means 96 pixels per inch(1 inch = 2.54 cm).there are 96 pixels per 2.54 cm. Then 1 pixel = (2.54 / 96) cm. We got 0.026458333 centimeters in a pixel.
you can multiply number of pixels in a row by 0.026458333.