2013-03-04 78 views
1

我有一个脚本,读取图像数据,然后遍历与scipy.ndimage中位数过滤器的图像。从迭代中我创建新的数组。ndimage脚本错误行为

然而,当我试图与

run filtering.py 

过滤运行脚本似乎并没有工作。新数组(month_f)与旧数组相同。

import matplotlib.pyplot as plt 
import numpy as numpy 
from scipy import ndimage 
import Image as Image 


# Get images 

#Load images 

jan1999 = Image.open('jan1999.tif') 
mar1999 = Image.open('mar1999.tif') 
may1999 = Image.open('may1999.tif') 
sep1999 = Image.open('sep1999.tif') 
dec1999 = Image.open('dec1999.tif') 
jan2000 = Image.open('jan2000.tif') 
feb2000 = Image.open('feb2000.tif') 

#Compute numpy arrays 

jan1999 = numpy.array(jan1999) 
mar1999 = numpy.array(mar1999) 
may1999 = numpy.array(may1999) 
sep1999 = numpy.array(sep1999) 
dec1999 = numpy.array(dec1999) 
jan2000 = numpy.array(jan2000) 
feb2000 = numpy.array(feb2000) 

########### Put arrays into a list 

months = [jan1999, mar1999, may1999, sep1999, dec1999, jan2000, feb2000] 


############ Filtering = 3,3 

months_f = [] 

for image in months: 
    image = scipy.ndimage.median_filter(image, size=(5,5)) 
    months_f.append(image) 

任何帮助,将不胜感激:)

回答

0

这是相当注释,但由于名声限制我不能写一个。

您导入模块的方式有点奇怪。特别是“进口..作为”与理想名称。我觉得更pythonian办法是

import matplotlib.pyplot as plt 
import numpy as np 
from scipy import ndimage 
from PIL import Image 

,然后调用

image = ndimage.median_filter(image, size=(...)) 

当我运行你的步骤,它似乎工作一个RGB测试图像。

jan1999.shape返回什么?

+0

ups,没有意识到这个问题太旧了...... – MrCyclophil 2015-11-16 17:41:55