2017-03-02 23 views

回答

0

有可能会在这里两个问题:

问题1:

它看起来像你的颜色通道(红,绿,蓝)混合。这可以解释为什么颜色太奇怪了。如果是这种情况,您将需要交换阵列中的颜色通道,如下所示。

import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib.cbook import get_sample_data 

rgb_image = plt.imread(get_sample_data("grace_hopper.png", asfileobj=False)) 

# correct color channels (R, G, B) 
plt.figure() 
plt.imshow(rgb_image) 
plt.axis('off') 

natural color

# swapped color channels (R, B, G) 
rgb_image = rgb_image[:, :, [0, 2, 1]] 
plt.figure() 
plt.imshow(rgb_image) 
plt.axis('off') 

swapped color channels

问题2:

Matplotlib的plt.imshow具有默认为None如果未指定关键字参数interpolation。 Matplotlib然后引用您的本地样式表来确定默认的插值行为。根据您的样式表,这可能会导致插值被应用,从而导致图像失真。请参阅documentation for imshow for more details

如果要确保Matplotlib不插入图像,则应在plt.imshow中指定interpolation="none"。这是令人困惑,因为的None默认NoneType值产生比"none"字符串值不同的行为。

red = np.zeros((100, 100, 3), dtype=np.uint8) 
red[:, :, 0] = 255 
red[40:60, 40:60, :] = 255 

# with interpolation 
plt.figure() 
plt.imshow(red, interpolation='bicubic') 
plt.axis('off') 

with interpolation

# without interpolation 
plt.figure() 
plt.imshow(red, interpolation='none') 
plt.axis('off') 

without interpolation

+1

随着Matplotlib 2.0的默认内插已变为' 'image.interpolation':“nearest'' –