使用 imwrite 创建的文件不出现
Matlab 新手,如果这是一个愚蠢的问题,我很抱歉。我正在为我的研究过滤一系列图像。我在实际图像处理方面没有遇到问题,但当我去保存修改后的图像时遇到了麻烦。由于某种原因,我只能使用 imwrite 将修改后的图像保存为 .gif 文件。如果我尝试将它们另存为 .jpg、.bmp 等,该文件不会出现在工作文件夹中。出现相应的通用文件,但实际的 .jpg 没有出现。此外,当我使用 imread 重新打开中间文件(实际上保存为 .gif)时,图像只是黑色。但是,如果我在 Matlab 之外打开 .gif 文件,它会按预期显示。代码如下。
close all
N=90;
IMAGES=cell(1,N); %creates a cell to store image data
FNAMEFMT='20110805115033(1)_%d.jpg';
for i=1:N
IMAGES{i}=imread(sprintf(FNAMEFMT,i)); %reads original images into IMAGES
end
RESULT=cell(1,N); %to store modified/filtered images
for i=1:N
gray=rgb2gray(IMAGES{i}); %converts to grayscale
binary=im2bw(gray,.5); %converts to bw
filter=bwareaopen(binary,35); %removes small features
RESULT{i}=filter; %saves modified image in RESULTS
end
for i=1:N
WRITEFMT='filter_%d';
imwrite(RESULT{i},sprintf(WRITEFMT,i),'gif'); %writes RESULTS as .gif
end
New to Matlab, so sorry if this is a silly question. I'm filtering a series images for my research. I'm not having a problem with the actual image processing, it's when I go to save the modified images that I run into trouble. For some reason, I can only save the modified images using imwrite as .gif files. If I try to save them as .jpg, .bmp, etc., the file does not appear in the working folder. The corresponding generic file appears, but the actual .jpg does not. Additionally, when I use imread to reopen the midified files (that actually saved as .gifs), the image is just black. But, if I open the .gif file outside Matlab, it appears as expected. Code below.
close all
N=90;
IMAGES=cell(1,N); %creates a cell to store image data
FNAMEFMT='20110805115033(1)_%d.jpg';
for i=1:N
IMAGES{i}=imread(sprintf(FNAMEFMT,i)); %reads original images into IMAGES
end
RESULT=cell(1,N); %to store modified/filtered images
for i=1:N
gray=rgb2gray(IMAGES{i}); %converts to grayscale
binary=im2bw(gray,.5); %converts to bw
filter=bwareaopen(binary,35); %removes small features
RESULT{i}=filter; %saves modified image in RESULTS
end
for i=1:N
WRITEFMT='filter_%d';
imwrite(RESULT{i},sprintf(WRITEFMT,i),'gif'); %writes RESULTS as .gif
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更改
为
您输出的文件是 jpeg 文件(根据 imwrite 参数 'jpg' 而不是 'gif'),但它们没有文件扩展名。如果您手动添加扩展名,它们会以 jpg 格式打开。
对于黑色 gif,看看这是否有帮助。
导出为 jpg 后,即可查看它们
You need to change
to
The files you are outputting are jpeg files (as per the imwrite argument 'jpg' instead of 'gif'), but they don't have a file extension. If you manually add the extension, they open as jpgs.
For the black gif, see if this helps.
Once you export as jpg, viewing them works