[英]imread function doesn't work in matlab
I am new to Image processing and learning matlab. 我是图像处理和学习Matlab的新手。 Actually till now I have used matlab cloud version where uploading an image was directly possible and didn't face any issue. 实际上,到目前为止,我已经使用过matlab云版本,可以直接上传图像并且没有任何问题。 But now I am facing an extreme problem of uploading an image in matlab offline version software. 但是现在我面临一个极端的问题,那就是在matlab离线版本软件中上传图片。
I imported an image by using "import data" 我使用“导入数据”导入了图像
Then I wrote this command 然后我写了这个命令
h = imread( 'digi1.jpg'); h = imread('digi1.jpg');
The problem you are experiencing comes from saving the data to a MATLAB data file, renaming the file with a .jpg
extension and trying to use imread
to read in the data. 您遇到的问题来自将数据保存到MATLAB数据文件,使用.jpg
扩展名重命名文件以及尝试使用imread
读取数据。
This unfortunately doesn't work. 不幸的是,这不起作用。 You can't change the file type of your data from .mat
to .jpg
. 您无法将数据的文件类型从.mat
更改为.jpg
。 All you're doing is changing what the name of the file is. 您要做的就是更改文件名。 You're not changing the contents of the file . 您没有更改文件的内容 。 Changing the file extension and name of the file does not mean that the contents will change. 更改文件扩展名和文件名并不意味着内容将更改。 Renaming it to digi1.jpg
would still make this file a MATLAB MAT file which you can only read with software that can read these files (Python, R, and yes MATLAB of course). 将其重命名为digi1.jpg
仍会使该文件成为MATLAB MAT文件,您只能使用可以读取这些文件的软件(Python,R,当然是MATLAB)读取该文件。
As such, try using load name.mat
(which is the name of your MAT file) in the command prompt. 因此,请尝试在命令提示符下使用load name.mat
(这是您的MAT文件的名称)。 This should give you the image already loaded into the workspace. 这应该给您已经加载到工作区中的图像。 Whatever that variable is called, use imwrite
to save the image to file. 无论调用imwrite
变量,都可以使用imwrite
将图像保存到文件中。
Assuming that the image was stored in a variable called A
, do something like this: 假设图像存储在名为A
的变量中,请执行以下操作:
>> load name.mat
>> imwrite(A, 'digi1.jpg');
Make sure name.mat
is in the current working directory of where you are trying to run the above code. 确保name.mat
在您试图运行上述代码的当前工作目录中。 You should now get an image saved on your disk. 现在,您应该将图像保存在磁盘上。 However, I would recommend you use something lossless instead of JPG if you want to maintain the quality of your image. 但是,如果您要保持图像质量,建议您使用无损替代JPG。 Try using PNG instead, so save your image as a .png
rather than .jpg
. 尝试改用PNG,因此将图像另存为.png
而不是.jpg
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.