MATLAB: Correlation between ‘FontSize’ for “insertText” function and resulting letter/textbox height in pixels

Computer Vision Toolbox

What is the correlation between 'FontSize' for "insertText" function and resulting letter/textbox height in pixels?
I would like to specify the size of the letters in pixels. For instance, I want the Letter 'A' to be x pixels high. I do not know how to achieve this using the 'FontSize' parameter as the correlation between the font size and the letter/textbox height in pixels is unknown. For instance what does 12 point font equal in pixels for the "insertText" function?

Best Answer

The "insertText" function uses TrueType fonts to render the text. TrueType is software that is embedded in both Windows and Mac operating systems and is outside of MATLAB. Currently there is no way for "insertText" to request the font height in pixels using the underling rendering library. However, once the font is rendered, the "insertText" function will "know" the font height in pixels but this value is currently inaccessible from outside the function.
As a workaround, you can measure the number of pixels of the output text to get the relationship between font height in pixels and the font size.
The workaround steps are as follows:
1. Select whatever string you wish to render.
2. Set the 'BoxOpacity' parameter of "insertText" to 1 to see the background box.
3. Use "imtool" function to measure the height of the box. "imtool" doc is linked below: