How to add a scale bar on an image that will changes automatically with zoom in/out

조회 수: 20 (최근 30일)
xi
xi 2019년 7월 3일
댓글: xi 2019년 7월 4일
Given an microscopy image, I want to add a scale bar on the bottom left or right corner of the image. This is not hard to do.
But when I zoom in to a small area of the image, the bar will go out of the screen. I want the scale bar to automatically adjust its length acording to the zoom ratio, and also a suitable label (e.g., 10um --> 5um --> 2um) and stay inside the image when I zoom in. How to realize it? I was trying to use the zoom(on) that enables the zoom tool of my axes, but then where to write the callback function that allows me to draw the scale bar everytime the mouse button (or scrollwheel) is clicked?

답변 (1개)

Image Analyst
Image Analyst 2019년 7월 3일
Try burning it into the image:
grayImage(row1:row2, column1:column2) = 255;
but if you pan, the bar may move out of the field of view. Otherwise you'll have to use rectangle() and each time you zoom or pan, you'll have to delete the old one, figure out the new size, and the new location, and draw a new one.
  댓글 수: 1
xi
xi 2019년 7월 4일
I think, I found the answer: use "ActionPreCallback", "ActionPostCallback" to find out the previous and current zoom ratio, and update the drawing of the scale bar. You are right that, I will have to delete the old one, figure out the size and location and draw a new one.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by