Rescale tick marks on UIAxes

4 次查看(过去 30 天)
I have a figure that represents a grayscale image. Its resolution is 1280x960. If I show the axes, this is what it shows. When I zoom in, I get the proper vector scaled axis tick marks.
I want to change the tick marks to be distance rather than resolution. I have created my own internal function that will determine pixel distance related to the scale given on the image.
For this note that:
pixel_distance = 0.1;
The image is attached. Here is the code I use to generate tick marks:
xlen = rescale(get(app.UIAxes,'xtick'),0,size(image,2)*pixel_distance);
ylen = rescale(get(app.UIAxes,'ytick'),0,size(image,1)*pixel_distance);
xt=arrayfun(@num2str,xlen,'un',0);
yt=arrayfun(@num2str,ylen,'un',0);
set(app.UIAxes,'xticklabel',xt,'yticklabel',yt)
set(app.UIAxes,'xtick',xlen,'ytick',ylen)
But this gives the wrong output:
If I just use this code:
xlen = rescale(get(app.UIAxes,'xtick'),0,size(image,2)*pixel_distance);
ylen = rescale(get(app.UIAxes,'ytick'),0,size(image,1)*pixel_distance);
xt=arrayfun(@num2str,xlen,'un',0);
yt=arrayfun(@num2str,ylen,'un',0);
set(app.UIAxes,'xticklabel',xt,'yticklabel',yt)
I am only setting the label string values but not the physical quantities. So when I scroll in the tick marks do not change as they should.
_______________
Does somebody know how I can correctly fix the scaling on the tick marks to represent distance rather than resolution?

采纳的回答

Image Analyst
Image Analyst 2022-8-31
Try passing in XData and YData as options into imshow
  2 个评论
Steven Manz
Steven Manz 2022-8-31
I just noticed that I forgot to include the image. It is included now. Sorry.
Steven Manz
Steven Manz 2022-8-31
Such a simple answer! Thank you so much. Here is the code I am now using. Instead of changing the axis on the backend like I was before. I am just doing it on the front end and using 'XData' and 'YData' to control the information.
function tick_update(app, image)
% Read in image
I = imread(image);
% Rescale
I = I(:,:,1);
% Determine pixel distance to properly scale everything
pixel_distance = find_numbers_and_spaces(I, app.ScalingEditField.Value);
% Tick Marks
xlen = size(image,2)*pixel_distance;
ylen = size(image,1)*pixel_distance;
% Create image
imshow(app.database.current_image,'Parent',app.UIAxes, 'XData',[0 xlen], 'YData', [0 ylen]);
end
Thanks again!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Feature Detection and Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by