使用 Matlab imwrite 将灰度图像保存为 JPEG
我是图像处理领域的新手,想就我无法解决的问题寻求帮助。问题如下:
我有一个灰色(黑白)图像“grayimage”,我想使用 Matlab 中的 imwrite
函数使用 JPEG 格式保存它。我使用以下语法:
imwrite(grayimage,cmap, 'imagename.jpg', 'jpeg');
现在,当我使用图像查看器打开图像文件 imagename.jpg 时,我看不到灰色图像。它的颜色和图像与预期不同。
谁能建议我做错了什么以及我在 imwrite
中缺少的选项/参数?
我想到将图像转换为RGB,然后以jpeg格式保存。这会有帮助吗?
I am new to the world of image processing and would like to seek help with an issue I could not figure out. The issue is as follows:
I have a gray (black and white) image 'grayimage' which I want to save using the imwrite
function in Matlab using JPEG format. I am using the following syntax:
imwrite(grayimage,cmap, 'imagename.jpg', 'jpeg');
Now, when I open the image file imagename.jpg using image viewers I don't see a gray image. It's colored and a different image than desired.
Can anyone suggest what I am doing wrong and options /parameters I am missing in imwrite
?
I thought of converting the image to RGB and then save it in jpeg format. Will that help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的cmap从哪里来?可能它是一个“彩色”色彩图。尝试使用灰色颜色图:
有关颜色图的更多信息:http://www.mathworks。 se/help/techdoc/ref/colormap.html
Where does your cmap comes from? Probably it is a "coloured" colormap. Try using a gray colormap:
More infos on colormap's: http://www.mathworks.se/help/techdoc/ref/colormap.html
在我看来,您有一个带有关联色彩图的索引图像。您可以使用 IND2GRAY 函数将其转换为灰度图像在使用 IMWRITE 将其保存到磁盘之前:
it seems to me you have an indexed image with an associated colormap. You could use the IND2GRAY function to convert it to a grayscale image before saving it to disk using IMWRITE:
欢迎来到有损压缩的世界。
如果您只想要灰度 jpeg,最简单的方法可能是安装
jpegtrans
程序并使用其-grayscale
选项来摆弄 图像的色度通道:更好的选择是使用 无损压缩格式,例如 png。
(感谢维基百科关于有损压缩的页面,以获得完美尺寸的彩色图像来摆弄。)
Welcome to the world of lossy compression.
If you simply want a grayscale jpeg, probably easiest would be to install the
jpegtrans
program and use its-grayscale
option to fiddle with the chrominance channel of the image:A better option would be to output using a lossless compression format such as png.
(Thanks to the Wikipedia page on lossy compression for a perfect-sized color image to fiddle with.)