Matlab中的颜色图和GIF图像 [英] Colormap and GIF images in Matlab

查看:171
本文介绍了Matlab中的颜色图和GIF图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理解Matlab中的颜色图并将其用于导入和显示.gif图像时遇到问题.

I have a problem understanding colormaps in Matlab and using them to import and diplay .gif images.

我想使用导入图像 im = imread('I.gif') 然后使用显示 imshow(im) 但是结果是错误的

I would like to import an image using im = imread('I.gif') and then display it using imshow(im) but the result is wrong

如果我愿意 [im,map] = imread('I.gif') 然后使用显示 imshow(即时贴图,地图) 它可以正常工作,但我仍然不了解此颜色图的必要性

If I do [im,map] = imread('I.gif') and then display it using imshow(im,map) it works properly, but still I don't understand the need of this colormap

有没有一种方法可以将我的gif图像导入并将其转换为灰度,以便在执行该操作时 imshow(im) 它可以显示正确的灰度图像,而不必担心颜色图?

Is there a way to import and convert my gif image to greyscale so that when I do imshow(im) it shows the correct greyscale image without having to worry about the colormap?

对noob问题很抱歉,但是我只是在Matlab中开始图像处理,因此我非常感谢您的帮助.这是我的第一个问题! :)

SOrry for the noob question but I am just starting with image processing in Matlab and I would really appreciate some help. It is my first question! :)

再见,谢谢!

推荐答案

如果要将gif转换为灰度,请使用

If you want to convert your gif to grayscale, use ind2gray:

[im,map] = imread('I.gif');
imGray = ind2gray(im,map);

需要颜色图的原因是gif格式不存储图像强度,而是将索引存储到颜色图中.因此,颜色0可以是红色或绿色或淡紫色.它是存储图像所需的实际RGB颜色的颜色图. ind2gray将采用每种颜色,将它们转换为灰度强度,然后用这些强度替换图像中的索引.

The reason that you need the colormap is that the gif format doesn't store image intensities, it stores indices into the colormap. So color 0 could be red or green or a very light shade of mauve. It's the colormap that stores the actual RGB colors that the image needs. ind2gray will take each of those colors, convert them to a grayscale intensity, and replace the indices in the image with those intensities.

这篇关于Matlab中的颜色图和GIF图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆