How do I save a figure with the desired size in pixels?

Hi everyone, I’m stuck with the following question: I want to save an image I created as a bmp-file with a size of 1080x1920 pixels. I just summarize how I crate my image:
- Creating a matrix Zeros(1080,1920)
- Imshow(matrix)
- Write a number on the current image using the text-command
Now, as described above, I would like to save the image as bmp, size 1080x1920 pixels. But it doesn’t work. No matter what I try (print, saveas…), I always get the wrong format. Usually it’s 1200x900. When I tried to set the resolution using the print command, I ended up with 1920x1440, which means it also somehow changed my aspect ratio. Can anyone help me out here?

 Accepted Answer

Use imwrite() and it will save the image in whatever resolution it has as the variable.
If you want to save the image as part of a larger picture of the figure, with graphical overlays and axes and stuff, then use export_fig() by Yair Altman (in the File Exchange)

3 Comments

Thank you for your reply, Image Analyst! Unfortunately it doesn't work, I tried but I get the following error: Error using imwrite (line 420) Expected DATA to be one of these types:
numeric, logical
Instead its type was matlab.graphics.primitive.Image.
Here is the part of the code I'm using, maybe there is a better way to do it?
curim = ones(1080, 1920);
myim = imshow(curim);
text(50, 50, num2str(i), 'FontSize', 50, 'Color', 'k')
imwrite(myim, 'test.bmp');
You're not writing the image - you're trying to write the figure, which is the window that the image is on, complete with any axes tick marks and the text you put on it. To do that you'd use export_fig(). Your initial post was not clear so that's why I gave you both ways, depending on exactly what you wanted to save.
With Export_fig() and a bit of playing around it works :) Thank you for your help!

Sign in to comment.

More Answers (0)

Categories

Find more on Images 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!