Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lock image dimensions in MATLAB

Tags:

image

size

matlab

So I have this matrix in MATLAB, 200 deep x 600 wide. It represents an image that is 2cm deep x 6cm wide. How can I plot this image so that it is locked into proper dimensions, i.e. 2cm x 6cm? If I use the image or imagesc commands it stretches it all out of shape and shows it the wrong size. Is there a way to lock it into showing an image where the x and y axes are proportional?

Second question, I need to then set this image into a 640x480 frame (20 pixel black margin on left and right, 280 pixel black margin on bottom). Is there a way to do this?

like image 947
Jordan Avatar asked Oct 11 '11 06:10

Jordan


1 Answers

To keep aspect ratio, you can use axis equal or axis image commands.

Quoting the documentation:

  • axis equal sets the aspect ratio so that the data units are the same in every direction. The aspect ratio of the x-, y-, and z-axis is adjusted automatically according to the range of data units in the x, y, and z directions.

  • axis image is the same as axis equal except that the plot box fits tightly around the data`

For second question:

third_dimension_size=1; %# for b&w images, use 3 for rgb
framed_image=squeeze(zeros(640,480,third_dimension_size));
framed_image(20:20+600-1,140:140+200-1)= my_600_200_image;

imagesc(framed_image'); axis image;
like image 124
Laurent' Avatar answered Sep 24 '22 09:09

Laurent'