Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pythons PIL(v2.6)中的TypeError消息:需要整数,得到浮点_Python_Python 2.7_Python Imaging Library_Typeerror - Fatal编程技术网

Pythons PIL(v2.6)中的TypeError消息:需要整数,得到浮点

Pythons PIL(v2.6)中的TypeError消息:需要整数,得到浮点,python,python-2.7,python-imaging-library,typeerror,Python,Python 2.7,Python Imaging Library,Typeerror,我第一次在论坛上。希望我说得够具体。 使用PIL中的ImageChops,我尝试将两个图像相乘(均为mode=“L”),但我总是得到相同的错误消息。我到处找了,但找不到有用的东西。我将非常感谢任何有用的想法! 守则的有关部分载于附件 def point(self, f, searchImage, technique): # technique - inpaint or bicubic dimx, dimy = searchImage.size reader = csv

我第一次在论坛上。希望我说得够具体。 使用PIL中的ImageChops,我尝试将两个图像相乘(均为mode=“L”),但我总是得到相同的错误消息。我到处找了,但找不到有用的东西。我将非常感谢任何有用的想法! 守则的有关部分载于附件

    def point(self, f, searchImage, technique): # technique - inpaint or bicubic

    dimx, dimy = searchImage.size

    reader = csv.reader(f)
    for line in reader: #f.readlines():
        coord = line
        print coord
        if searchImage.size[0] > float(coord[0])+95.5 and searchImage.size[1]\
           > float(coord[1])+95.5: 
            box = (float(coord[0])-93.5,float(coord[1])-93.5,\
                   float(coord[0])+95.5,float(coord[1])+95.5)     # left upper right
        elif searchImage.size[0] < float(coord[0])+95.5 and searchImage.size[1]\
             > float(coord[1])+95.5:
            box = (float(coord[0])-93.5,float(coord[1])-93.5,\
                   searchImage.size[0]-0.5,float(coord[1])+95.5)  # size of box
            # depends on pixel size. A pixel size of 14 micrometer results in a
            # cross size of 189 pixels
        else:
            box = (float(coord[0])-93.5,float(coord[1])-93.5,\
                   float(coord[0])+95.5,searchImage.size[1]-0.5)

        box = (math.floor(box[0]), math.floor(box[1]), math.floor(box[2]),\
               math.floor(box[3])) 

        searchCrop = searchImage.crop(box)

        c_x = int(float(coord[1])) 
        c_y = int(float(coord[0])) 
        abst_y = c_x - int(math.floor(box[1])) - 1 # x shift

        center = num.asarray(searchImage)[c_x,c_y]
        if center == 0:
            center = center + 0.00001 # to avoid division by zero
        val = [num.asarray(searchImage)[c_x-1,c_y+1], num.asarray(searchImage)\
               [c_x-1,c_y-1], num.asarray(searchImage)[c_x+1,c_y-1], \
               num.asarray(searchImage)[c_x+1,c_y+1]] # ERDAS upper right,
        # upper left, lower left, lower right

        val_dict = {0:1,1:-1,2:-1,3:1}
        flag = val_dict[val.index(min(val))]
        if float(min(val))/center > 2. or min(val) > 100:
            flag = 0

        newima = num.zeros( (searchCrop.size[1], searchCrop.size[0]),\
                            dtype = "float")

        Ayo = num.array(int(searchCrop.size[0])*[255]) 
        Ay = num.array((abst_y + flag)*[255] + 3*[0] + ((int(searchCrop.size[0]\
                                                             )-3-abst_y)-flag)*[255]) 
        Ax = num.array(int(searchCrop.size[0])*[0])  
        Kx = num.array(3*[Ayo] + ((int(searchCrop.size[1])-9)/2+flag)*[Ay] + 3*[Ax] \
                       + ((int(searchCrop.size[1])-9)/2-flag)*[Ay] + 3*[Ayo])   

        Kxlist = list(itertools.chain(*Kx))

        i=0
        for y in range(int(searchCrop.size[1])): 
            for x in range(int(searchCrop.size[0])):        
                newima[y,x] = Kxlist[i+y+x]
            i=i+x

        kernel = Image.fromarray(newima)
        kernel = kernel.convert(mode="L")

        # -----
        modified = ImageChops.multiply(searchCrop,kernel)   # Results in an image 
        # where the pixels along the cross axes will get a value of 0
        # ---

问题是,PIL的crop方法接受4个整数值的元组,但传递的是浮点值。这应该起作用:


box=tuple([int(math.floor(x))表示框中的x])

选中
searchCrop=searchImage.crop(box)
。这是您共享的代码中唯一一段似乎在调用该函数的代码,据我所知,框值可能会在其他值之前设置好。
File "D:\GIS_dbase\Data\hma_cci\hexagon\KH9_Python\interpolate_cross.py", line 58, in 
 crossInterpolation filledImage = self.p_model.point(f, searchImage, method) 
File "D:\GIS_dbase\Data\hma_cci\hexagon\KH9_Python\interpolate_cross.py", line 207, in 
 point modified = ImageChops.multiply(searchCrop,kernel)   # Results in an image where 
 the pixels along the cross axes will get a value of 0
File "C:\Python27\lib\site-packages\PIL\ImageChops.py", line 119, in multiply
 image1.load()
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1730, in load
 self.im = self.im.crop(self.__crop)
TypeError: integer argument expected, got float