Stacked image plot with custom x-axis help
Show older comments
Dear Sirs,
I am working on a utility that will plot a stack of identically-sized RGB images, and allow the user to zoom and pan the set as a group.
Both x and y axes have a relationship to linear distance, and I would like that to be reflected in the numeric tick-marks in the plot, but so far I have not found a satisfactory solution.
I have tried building the stack with image(...) calls, which gives me a stack that zooms/pans properly in pixels, but I don't know how to display distances on the x-axis. If I use imshow(image, 'XData', ...) the plots are compressed in the x-direction (as if it is taking the numerical value, and using that in pixels), but I think it is still zooming/panning OK.
Ideally, I'd like the tool-tip to report the modified X value as well, and draw a vertical line through all plots of the stack. My code is below:
function showImages(sampleImage)
% from phantom data calibrated
scaleFactor = 0.0578; % mm/pixel
% For labelling
fullImageWidth = size(sampleImage, 2);
fullImageWidthPixels = 1:fullImageWidth;
fullImageWidthmm = zeros(1, fullImageWidth);
flippedPixels = fliplr(fullImageWidthPixels);
if rem(fullImageWidth, 2) == 0
% width is even pixels, so dividing by 2 will yield whole
% numbers
fullImageWidthmm(1:fullImageWidth/2) = flippedPixels((fullImageWidth/2)+1:end) * -scaleFactor;
fullImageWidthmm(fullImageWidth/2 + 1: end) = fullImageWidthPixels(1:fullImageWidth/2) * scaleFactor;
else
fullImageWidthmm(1:(fullImageWidth - 1)/2) = flippedPixels((fullImageWidth/2)+1:end) * -scaleFactor;
fullImageWidthmm((fullImageWidth + 1)/2:end) = fullImageWidthPixels(1:fullImageWidth/2) * scaleFactor;
end
% plot stack of images
figure();
t=tiledlayout('vertical','TileSpacing','tight','Padding','tight');
for i=1:5
h(i)=nexttile();
imshow(sampleImage, 'XData', fullImageWidthmm);
%image(sampleImage);
end
axis on;
% make all plots scale together
linkaxes(h);
end
I have attached a sample image.
Thanks!
Duane
Accepted Answer
More Answers (0)
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!