Why does MATLAB resample display data for *some* large images and not others? Can this be turned off?
14 次查看(过去 30 天)
显示 更早的评论
When displaying large images (i.e. images with dimension greater than the screen resolution) using IMSHOW, IMAGESC, and similar functions, MATLAB will downsample the displayed image (CData not manipulated). However, this only happens when my image has dimension below 2048 pixels (i.e. images with dimension larger than 2048 do not have display data manipulated). This can be demonstrated by simply padding an image just under 2048 pixels and zooming in on an area of high detail. Why? How can this be avoided? Example below.
% Create image with dimension = 2048
im = zeros(2048);
% Draw line pair down center of image
im(:,[1000,1002]) = 1;
% Display and zoom in (no line pair)
figure; imshow(im)
% Display portion of image with dimensions within screen resolution (line pairs visible)
figure; imshow(im(1:1010,1:1010))
% Create new image with dimension = 2049 (or larger)
im2 = zeros(2049);
% Draw line pair down center of image
im2(:,[1000,1002]) = 1;
% Display and zoom in (line pair now visible)
figure; imshow(im2)
0 个评论
回答(1 个)
Image Analyst
2017-1-11
I think it just depends on what rows and columns it decides to use when it does the resampling. For one case it might decide to use column 1000 with the line and you'll see it, and in another case it might decide to use column 1001 with no line and not use the 1000 line, so the line doesn't show up. It's downsampling in both cases, it's just using different sets of pixels.
5 个评论
Image Analyst
2017-1-12
Something's gone wrong with their attachment thing. I definitely attached it and now it's gone. Plus, I've tried 4 times to attach it just now with the paperclip icon, and it won't take it. It doesn't give any error message or anything, it just doesn't do the attachment. It must be a bug. I'll tell Rena about this tomorrow. In the meantime, here is the demo I got from the Mathworks, with slight modifications by me.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 13;
% IMSHOW has historically had this behavior all the way back to 1993, that is, it shows the whole image.
% If it can show the whole image at “truesize” or more recently called 100, it does,
% but if not, it shows the whole image.
% When we introduced IMTOOL and IMSCROLLPANEL, there’s more flexibility with the display
% because the scroll panel shows you that there is more image there beyond what you can see.
% Have you tried using IMSCROLLPANEL in combination with IMSHOW? See example below or in:
% doc imscrollpanel
%
% It allows you to directly set the magnification, programmatically or through a magnification box.
% When we created IMSCROLLPANEL and the associated magnification controls in IPT5, we hoped that they would satisfy exactly this GUI use case.
%
% Let me know what you think if you try it or if you've tried it in the past, why it doesn't meet your needs.
% We're open to discussing this further with you to see if we can fix the issue or make the better solution easier to discover if it's indeed adequate.
% Here's the example from the documentation:
% Create a scroll panel with a Magnification Box and an Overview tool.
hFig = figure('Toolbar','none',...
'Menubar','none');
hIm = imshow('saturn.png');
hSP = imscrollpanel(hFig,hIm); % Handle to scroll panel.
set(hSP,'Units','normalized',...
'Position',[0 .1 1 .9])
% Add a Magnification Box and an Overview tool.
hMagBox = immagbox(hFig,hIm);
pos = get(hMagBox,'Position');
set(hMagBox,'Position',[0 0 pos(3) pos(4)])
imoverview(hIm)
% Get the scroll panel API to programmatically control the view.
api = iptgetapi(hSP);
% Get the current magnification and position.
mag = api.getMagnification();
r = api.getVisibleImageRect();
% View the top left corner of the image.
message = sprintf('Click OK to view the top left corner of the image');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setVisibleLocation(0.5,0.5)
% Change the magnification to the value that just fits.
message = sprintf('Click OK to change the magnification to the value that just fits');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setMagnification(api.findFitMag())
% Zoom in to 1600% on the dark spot.
message = sprintf('Click OK to zoom in to 1600%%on the dark spot.');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setMagnificationAndCenter(16,306,800)
% Zoom in to 100% with upper left showing.
message = sprintf('Click OK to zoom in to exactly 100%%.');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setMagnificationAndCenter(1,1,100)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!