简体   繁体   English

如何在Matlab中保存图像

[英]How to Save an image in matlab

I use the below command to display the image 我使用以下命令显示图像

imshow(img,[]);

when i use the following command to save the image it is saved as an empty white page 当我使用以下命令保存图像时,将其另存为空白页

imsave;

how to save the image in this case any command would do 在这种情况下,如何保存图像,任何命令都可以

Convert image data into an actual image and try again: 将图像数据转换为实际图像,然后重试:

h = image(img); %Convert to object
imsave(h); %Save image object

Notice that if you close the figure window generated by image() , the object is deleted and the handle has will point to nothing. 注意,如果关闭由image()生成的图形窗口,则该对象将被删除,并且该句柄将指向无。 Though this may be beyond of what you are asking for. 尽管这可能超出您的要求。

Hope this adjustment solved your problem 希望这次调整能解决您的问题

You are probably running into an issue with matrix type and range. 您可能会遇到矩阵类型和范围的问题。 If img is type double it needs to be scaled between 0 and 1. 如果imgdouble类型,则需要在0到1之间缩放。

A common issue is to load an image in uint8 (scaled between 0 and 255), convert to double in order to do some processing on it, without scaling, and then try and save it out. 一个常见的问题是将图像加载到uint8 (缩放比例在0到255之间),转换为double尺寸以便对其进行一些处理而不进行缩放,然后尝试将其保存。 When you do that, MATLAB tries to convert back to uint8 , and any values in the image outside the [0 1] range are clipped. 当您这样做时,MATLAB尝试转换回uint8 ,并且图像中[0 1]范围以外的任何值都会被裁剪。 On many images this means that the file comes out all white. 在许多图像上,这意味着文件全为白色。

To get around this, use functions like im2double and im2uint8 rather than just double or uint8 when converting images. 要解决此问题,在转换图像时,请使用诸如im2doubleim2uint8类的im2double ,而不要仅使用doubleuint8

Try at the command line the difference between: 尝试在命令行之间进行区别:

img = imread('pout.tif');
img = double(img);
imshow(img,[]);
imsave; 

and

img = imread('pout.tif');
img = im2double(img);
imshow(img,[]);
imsave; 

First convert the image to rgb using 首先使用将图像转换为rgb

img1=label2rgb(img);

then again convert the image into an gray image using 然后再次使用将图像转换为灰度图像

img2=rgb2gray(img1);

then u can use imshow to show the image and save it using imsave 然后您可以使用imshow显示图像并使用imsave保存

imshow(img2);
imsave();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM