Borrar filtros
Borrar filtros

Rescale tick marks on UIAxes

3 visualizaciones (últimos 30 días)
Steven Manz
Steven Manz el 31 de Ag. de 2022
Comentada: Steven Manz el 31 de Ag. de 2022
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?

Respuesta aceptada

Image Analyst
Image Analyst el 31 de Ag. de 2022
Try passing in XData and YData as options into imshow
  2 comentarios
Steven Manz
Steven Manz el 31 de Ag. de 2022
I just noticed that I forgot to include the image. It is included now. Sorry.
Steven Manz
Steven Manz el 31 de Ag. de 2022
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!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by