How do I scale the units of a displayed image?

7 views (last 30 days)
Some of the images I display have real-world pixels sizes of, say, 0.5m, and some have sizes of, say, 2m. When I display the image, I'd like the x and y axes to scale appropriately and show units of meters instead of pixels.
I can get the XTickLabel and YTickLabel arrays for both axes and multiply them by the appropriate scaling factor (after converting the cell arrays to doubles, then converting back to cell arrays afterwards). But when I interact with the image (using the pan or zoom tools), the tick mark labels get screwed up.
For example - at left is my full image after scaling the axes tick marks to show size in meters. The actual image is 2347x2174, but since they're 0.5m pixels, the axes limits are half that. At right is the image afer zooming in on the large feature in the middle. The tick mark labels are incorrect.
It seems that Matlab is taking my manually-set Tick Labels and applying them to the image in 1-N order, no matter what tick marks correspond to the current pan and zoom levels of the image. Is this a bug, or is there something I'm not doing to keep the manual Tick Labels dynamic?
Thanks.
  1 Comment
Tom Repetti
Tom Repetti on 26 Apr 2021
Ah. Discovered the xticks and xticklabels functions (and even the ones for the y and z axes). Nice. Would be even nicer if there was a global scale factor one could apply to tick labels so that one could zoom and pan an image and let the tick marks stay auto-determined but the tick labels remain scaled, but you can't have everything.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 26 Apr 2021
You can put in the axes limits into imshow() with the 'XData', and 'YData' options.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!