For instance, how do I make X,Y appear as mm and not pixels, see the image.
How to turn pixel values to mm on axes
30 views (last 30 days)
Show older comments
Hello
As far as I know, Matlab plots give X,Y in pixel values. How do I turn them to units of length? E.g. milimeters? mm. I want X,Y values to appear as mm.
Thanks
2 Comments
Stephen23
on 9 Jan 2019
"As far as I know, Matlab plots give X,Y in pixel values"
Can you give a link to the documentation where this is stated?
Accepted Answer
Totanly
on 8 Jan 2019
first find, how many pixels =1mm?
suppose10 pixel=1mm;
X_in_mm=X./10;
Y_in_mm=y./10;
xlabel('x in mm')
ylabel('y in mm')
3 Comments
Stephen23
on 9 Jan 2019
@Stelios Fanourakis: read Walter Roberson's answer, it gives a very brief outline of what you will need to consider. You approach is far too simplistic, and is based on incorrect assumptions (i.e. "As far as I know, Matlab plots give X,Y in pixel values").
More Answers (1)
Walter Roberson
on 8 Jan 2019
No, all graphics that takes place within an axes is in data units, not in pixels. Your label of 300 in your example is 300 data units, not 300 pixels. If you were to resize the axis the labels would move proportionately but would not change.
If 10 of your input units are intended to represent 1 mm, then you can plot(X./10, Y./10) . Note that this will just change the effective labels (and data cursor information) but will not change the fact that these will be data units, and that they will take more or less screen space depending how you resize your axis.
If you need 10 data units to correspond to 1 real-world mm (so like you could put a ruler up against the screen and measure it as 1 mm) then you need to set the Axes Units property and you need to be careful about your xlim and ylim and data aspect specification.
But even if you get those all right in theory, in practice they will likely be wrong unless you are working with a high quality calibrated display. Most displays report nominal resolution, but if you go to an "Office Supply" store that sells monitors and you compare two monitors with different screen sizes but the same number of pixels, you will often find that they both report the same nominal resolution. The user controls given on monitors also affect the real-world resolution, and not necessarily linearly. (CRT are subject to pincushion and barreling for example.)
15 Comments
Walter Roberson
on 10 Jan 2019
Please run the attached code and post the results.
On my system the result is
A 15" screen is about 380mm diagonal
A 17" screen is about 430mm diagonal
A 21" screen is about 530mm diagonal
A 27" screen is about 680mm diagonal
What is the physical measurement of the diagonal of your display, in mm ? 680
graphics thinks image size is x=1366 pixels, y=651 pixels
graphics thinks image size is x=481.894 mm, y=229.658 mm
figure estimates pixels/mm as x=2.83465, y=2.83465
actual image size is x=1366 pixels, y=651 pixels
Hardware screen size is x=1 pixels, y=1 pixels
Hardware screen size is x=2560 pixels, y=1440 pixels
Graphics subsystem "official" pixels per mm is: 2.83465
Physical pixels per mm is about: 4.31943
Ratio of physical pixels per mm to "official" pixels per mm is about: 1.5238
hardware estimate of physical image size is x=316.246mm, y=150.714mm
The difference between physical pixels and "official" pixels has to do with the treatment of High DPI displays. In recent versions of MATLAB, on Mac there are officially 72 pixels per inch, and on Windows there are officially 96 pixels per inch under some circumstances; see https://www.mathworks.com/help/matlab/creating_guis/dpi-aware-behavior-in-matlab.html .
Notice that the physical pixels per mm for my display is over 4 times your claim of about 1.09 .
The physical measurement of the images was 315 mm by 152 mm (measured with a tape measure) -- in agreement with the hardware estimated image size and not what the graphics system would suggest the size would be.
Thus, the physical output size is best calculated as number of image pixels divided by physical pixels per mm. Unfortunately you may need the user input about the physical screen size in order to calculate this.
Stephen23
on 10 Jan 2019
Edited: Stephen23
on 10 Jan 2019
"Well using a calibration tool,..."
Measuring what exactly:
- something displayed on a particular screen, or
- data stored in an image file, or
- ...something else?
"I found that a distance of 400 mm in the image include 435.6 pixels"
That pixel density might match an old B+W TV. Unusual, to say the least... unless of course you were actually just measuring an image displayed on your screen at some arbitrary scaling (so that the image pixels do not have a one-to-one correspondence with the screen pixels, as is almost always the case these days). If that were the case you would still need to get/measure the screen pixel density and use the factor based on that "calibration" measurement.
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!