问题描述
我刚开始使用Python和图像处理试验。我跟着这个非常良好的结构教程: http://pythonvision.org/basic-tutorial/ 。在本教程的一切似乎都在工作,所提供的图像(一个与细胞)。现在我想试试这个怎么输入另一个图像时的行为。所以我把另一个图像(一个在这个岗位的底部),突然的东西是表现不同。首先, pylab.show()
不显示图像热图,但常规的图像,而它应该给热图时没有颜色映射定义的。
I just started experimenting with Python and image processing. I followed this very well structured tutorial: http://pythonvision.org/basic-tutorial/ . Everything in the tutorial seems to work, with the image provided (the one with the cells). Now I wanted to try how this behaves when inputting another image. So I took another image (the one at the bottom of this post) and suddenly stuff is behaving differently. First off, pylab.show()
doesn't show the image heatmap but the regular image, while it should give the heatmap when no colormap is defined.
由于这一切的原因是行为不同,它只能识别一个组件(一切,是不是白色)。我在想什么?是否将输入图像必须是黑白/灰度?是否显示.jpg和JPEG格式有关系吗?
As a cause of this everything is behaving differently and it only recognises one component (everything that is not white). What am I missing? Does the input image have to be black and white/ grayscale? Does .jpg and .jpeg matter?
我似乎无法找出问题所在,帮助将AP preciated。
I can't seem to find the problem, help would be appreciated.
这code应该给默认的热图的看法,但给人的常规形象,而不是:
This code should give the default heatmap view but gives the regular image instead:
dna = mahotas.imread('tools.jpg')
dna = dna.squeeze()
pylab.imshow(dna)
pylab.show()
在此先感谢。
Thanks in advance.
图片我试图使用方法:
The image I'm trying to use:
推荐答案
最有可能你输入的图像是三通道(R,G,B),示例图像灰度/ 1路。 Matplotlib将尝试一个颜色表应用到1通道图像,但将呈现三通道原样。您可以使用scikit图像下变频:
Most likely the image you're inputting is three channel (r,g,b) and the example image is grayscale/1-channel. Matplotlib will try to apply a colormap to a 1-channel image, but will render the three-channel as is. You can use scikit-image to downconvert:
from skimage.color import rgb2gray
img_gray = rgb2gray(img)
pylab.imshow(img_gray)
您正在使用的图像处理库可能也有这些颜色的转换程序。
The library you're using for image processing may also have these color-conversion utilities.
这篇关于Python的图像教程作品,其他图像表现diferently(与Pylab显示图像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!