uiaxes restore not returning to original view follow zoom on image
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Working with Matlab app, placing a image within a UIaxes in a uitab. The image is added with imagesc, axis set to equal, and a colorbar added. A toolbar is attached to the uiaxes using the axtoolbar(ax,{}) command, and a button added with the Userdata =uiaxes.Position prior to displaying the image. Zooming the image with drawn rectangle results in reduced length or width of the image axes, and using a the toolbar "restore" results in a view of the full image within the reduced image axes. Trying to restore the position of the axes through a callback to a new toolbar button is unsuccessful, as the callback event returns an axes object which has parent uiaxes, neither of which have position matrices matching the position used to create the original uiaxes, and assigning the original position array to these objects doesn't restore the view to the original size. Is there a mechanism to get the uiaxes to behave so that scaling is preserved and the axes viewing area remains a fixed size? Portions of code shown below.
function [results,btn] = MakeTab(app,tabName)
% create a new tab in the image tab group with an axis
results = uitab(app.Images,"Title",tabName);
% attach an axis for drawing an image
haxis = uiaxes(results,'Position',app.axisPosition,'Box','on');
% set up the axis toolbar
thistoolbar = axtoolbar(haxis,{'datacursor','pan','zoomin','zoomout','restoreview'});
% define the restoreview callback to include resizing the axis
btn = axtoolbarbtn(thistoolbar,'push');
btn.Icon = 'ReSize_Icon.png';
btn.Tooltip = 'Resize Image';
btn.ButtonPushedFcn = @ForceAxisSize;
btn.UserData = app.axisPosition;
end
function ForceAxisSize(src,evt)
evt.Axes.Position = src.UserData;
%zoom(evt.Axes.Parent,1);
drawnow;
end
function [haxis,himage] = DisplayFilmImage(ThisAxis,ImageData,CenterRow,CenterCol,XPixelSize,YPixelSize,DisplayUnits,ColorMap)
[NumRow,NumCol] = size(ImageData);
[XStart,XFinish] = CalcImageDataRange(NumCol,XPixelSize,CenterCol);
[YStart,YFinish] = CalcImageDataRange(NumRow,YPixelSize,CenterRow);
% put in range limiting tests to prevent satuartion in the noise
CRangeLimit = 0.999;
CRangeMargin = 1.05;
BinCount = 200;
% bin the intensities in a histogram
[BinnedArray,BinLevels] = histcounts(ImageData,BinCount);
% sum the array
CummArray = cumsum(BinnedArray);
CummArray = CummArray/CummArray(end);
% find the level at which we achieve the set limit
MaxRange = CRangeMargin * BinLevels(find(CummArray > CRangeLimit,1,'first'));
if isempty(MaxRange) || MaxRange == 0
MaxRange = 1;
end
if isempty(ThisAxis)
himage = imagesc(ImageData, 'XData', [XStart,XFinish], 'YData', [YStart,YFinish],[0,MaxRange]);
else
himage = imagesc(ThisAxis,ImageData, 'XData', [XStart,XFinish], 'YData', [YStart,YFinish],[0,MaxRange]);
end
haxis = himage.Parent;
axis(haxis,'equal');
colormap(haxis,ColorMap);
colorbar(haxis);
haxis.YDir = 'normal';
haxis.XLabel.String = ['Width (' DisplayUnits ')'];
haxis.XLabel.FontSize = 12;
haxis.YLabel.String = ['Length (' DisplayUnits ')'];
haxis.YLabel.FontSize = 12;
end
Views of image
Original:
Following Zoom:
Restore after zoom:
0 comentarios
Respuestas (1)
Prathamesh
el 18 de Ag. de 2023
Hi,
I understand that when you try to zoom in the “uiimage” the aspect ratio of the image changes.
You can try setting the aspect ratio property of the axes to [1 1 1] which will maintain the scaling while zooming in or zooming out.
ax = axes;
ax.DataAspectRatio = [1 1 1];
Refer to the documentation below to get more information.
For restoring the zoomed image, you can try to set axis limits to the original limits.
xLimits = xlim;
yLimits = ylim;
% Zoom in on a specific region of interest
zoom(2); % Zoom in by a factor of 2
% Restore the original image size and axis
xlim(xLimits);
ylim(yLimits);
Refer to the documentation below for more information.
0 comentarios
Ver también
Categorías
Más información sobre Data Exploration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!