How to get image of figure with exact same size after saving on computer

I would like to save image from a figure with exact same size. I have used export setup for specific size (e.g. points) of image. However, it becomes a different dimension after saving on computer memory. Is there any way to get the image of that figure with exact same size after saving it.

回答 (1 件)

Image Analyst
Image Analyst 2019 年 9 月 22 日

0 投票

Using saveas() or export_fig() will give you an image the same size in pixels as the displayed figure.
If you have an axes on that figure and want just the stuff in the axes, you can use getimage() or getframe() to get an image.
If you have an image, you can use imwrite() and that will save it with the same size.

8 件のコメント

Rafi Ahmed
Rafi Ahmed 2019 年 9 月 22 日
編集済み: Rafi Ahmed 2019 年 9 月 22 日
when I use saveas(gcf,'fd90azminus4el70.jpg'), it saves the image like the attached one. It has white pixels around the whole image. I just want the picture without these white pixels.
Image Analyst
Image Analyst 2019 年 9 月 22 日
Where did the image come from? Is it a graph/plot? Or an image?
saveas() saves the whole window including the surrounding padding/white space.
How did you create the picture in the axes on the figure that you saved with saveas()? Did you use plot() or imshow() or image() or imagesc() or pcolor() or something else?
Did you try my other suggestions of getframe(), getimage(), or imwrite()?
Rafi Ahmed
Rafi Ahmed 2019 年 9 月 22 日
編集済み: Rafi Ahmed 2019 年 9 月 22 日
Hello,
Sir, I used pcolor to get the image. I have used getframe(), getimage() and imwrite(). getImage() and imwrite() are not working. getframe() yields paddings surrounding the image. I have attached the matrix of power values.
fdop = -180:179;
phi = -180:179;
figure,
[Az Doppler] = meshgrid(sin(phi*pi/180),fdop);
pxx = % matrix of power values (360x360 matrix)
mp = pcolor(Az, Doppler, 10*log10(pxx));
Rafi Ahmed
Rafi Ahmed 2019 年 9 月 25 日
Sir,
Do you think it is possible to get the figure with exact same size (360x360) from pcolor command?
Walter Roberson
Walter Roberson 2019 年 9 月 25 日
編集済み: Walter Roberson 2019 年 9 月 25 日
If you want to save only what is pcolor'd, then do not use pcolor() and saveas()
Use arcsin(linspace(0,1,WidthOfOutputImage)) to get x coordinates to use in your matrix of power values. That is, your meshgrid() with sin() makes for a non-linear pcolor output, and you need to linearize it by finding the x values that map into each output pixel wide.
mat2gray() to map 10*log10(pxx) to the range 0 to 1, and then multiply by the number of entries in the colormap you are using, floor(), uint8() and ind2rgb() with that colormap. The result should be an RGB image.
Rafi Ahmed
Rafi Ahmed 2019 年 9 月 25 日
Sir,
Thanks for your comment. I could not understand the procedure. Would you please explain the process of linearizing the values?
You have
[Az Doppler] = meshgrid(sin(phi*pi/180),fdop);
so Az will be "sin spaced" apart -- closer together near -180, 0, and +180 than near +-90 degrees. When you then use Az as the x coordinate for pcolor, it has to put the elements closer together or further apart because of that.The distance between adjacent values is not constant with what you are doing now. But when you create an image, the distance between adjacent values (pixels) is constant. So you have to substitute in original non-linearly spaced phi coordinates such that sin() of them translates after the sin() to be linearly spaced.
However, I just realized that you have a problem: for each x value in the range (-1,1) exclusive, there are two phi values that map to that same x value. Your surface folds back on itself, and you need to decide which of the folds is the one that you want to appear in the output.
Rafi Ahmed
Rafi Ahmed 2019 年 9 月 25 日
編集済み: Rafi Ahmed 2019 年 9 月 25 日
Sir,
Yes you are right. The values fold back and I need all of them in one image. I guess, there is no option but to use pcolor for that. But I could not understand that if I have the figure, why couldn't I save the figure with the size of 360x360 dimension? It is always converted into another dimension (e.g. 525x700) when saving on computer memory. When I resize it to 360x360, it has some loss probably. Do you think that, resizing image has better solution?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

製品

リリース

R2018b

質問済み:

2019 年 9 月 22 日

編集済み:

2019 年 9 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by