In most cases, you will be very happy with the way Matlab displays images. But if you are like me, who likes to display images in a predetermined position you may want to read further.
% Lets read the image of lenna in the matrix A
Here (1, 1) are the co-ordinates of the left bottom point of the screen and (1680, 1028) is the top-right point.
In the above code (x_lowerbottom, y_lowerbottom) is the co-ordinate of the point on the screen where your figure's lower bottom point will be displayed!
This is confusing a bit. But don't worry, unless you are a control freak like me, you may never be using this ... ever!
% Lets read the image of lenna in the matrix A
A=imread('lenna.jpg');
figure; % this opens up a new figure.
imshow(A); % Displays the image A
This will display the image. But if you want to control the position of your image on your computer screen you can try playing with the code below.
figure;
screen_size=get(0,'screensize')
% this is your computer's screen % size
screen_width=screen_size(3); % width of the screen
screen_height=screen_size(4); % height of the screen
figure_width=screen_size(4)/2; % width of the figure
figure_height=screen_size(4)/2; % height of the figure
x_lowerbottom=(screen_width-figure_width)/2;
y_lowerbottom=(screen_height-figure_height)/2;
set(gcf,'position',[x_lowerbottom y_lowerbottom figure_width figure_height]);
imagesc(A);
colormap('Gray');
For my computer the command screen_size=get(0,'screen size') displays the following in the command window.
screen_size =
1 1 1680 1028
Here (1, 1) are the co-ordinates of the left bottom point of the screen and (1680, 1028) is the top-right point.
In the above code (x_lowerbottom, y_lowerbottom) is the co-ordinate of the point on the screen where your figure's lower bottom point will be displayed!
This is confusing a bit. But don't worry, unless you are a control freak like me, you may never be using this ... ever!
No comments:
Post a Comment