How to turn pixel values to mm on axes

23 次查看(过去 30 天)
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 个评论
Stelios Fanourakis
For instance, how do I make X,Y appear as mm and not pixels, see the image.
Stephen23
Stephen23 2019-1-9
"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?

请先登录,再进行评论。

采纳的回答

Totanly
Totanly 2019-1-8
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 个评论
Stelios Fanourakis
1 mm of length corresponds to 1.09 pixels. I use that script. Is it correct how stated? I don't see much of difference.
figure
X=X./1.09;
Y=Y./1.09;
A=contour(mask,'b')
set(gca,'ydir','reverse',X,Y)
Stephen23
Stephen23 2019-1-9
@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").

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2019-1-8
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 个评论
Walter Roberson
Walter Roberson 2019-1-10
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
Stephen23 2019-1-10
编辑:Stephen23 2019-1-10
"Well using a calibration tool,..."
Measuring what exactly:
  1. something displayed on a particular screen, or
  2. data stored in an image file, or
  3. ...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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by