MATLAB: How to display image from system folders..??

pepper.pngsun.png

clear
[X1,map1]=imread('C:\Users\SONY\Downloads\abcd.jpg');
[X2,map2]=imread('C:\Users\SONY\Downloads\abcd.jpg');
subplot(1,2,1), subimage(X1,map1)
subplot(1,2,2), subimage(X2,map2)

Best Answer

Try using imshow() instead of subimage() (whatever that is):
clear
[X1, map1] = imread('C:\Users\SONY\Downloads\abcd.jpg');
[X2, map2] = imread('C:\Users\SONY\Downloads\abcd.jpg');
subplot(1, 2, 1);
imshow(X1, map1)
subplot(1, 2, 2);
imshow(X2, map2)
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'My Images', 'NumberTitle', 'Off')
You should really make it more robust by checking if the filenames exist first, with the exist(filename, 'file') function, before trying to call imread() and then warn the user if they don't exist:
filename = 'C:\Users\SONY\Downloads\abcd.jpg';
if exist(filename, 'file')
[X1, map1] = imread('C:\Users\SONY\Downloads\abcd.jpg');
subplot(1, 2, 1);
imshow(X1, map1)
else
warningMessage = sprintf('Warning: the image file does not exist:\n%s', filename);
uiwait(warndlg(filename));
end
Related Question