TypeError message in Pythons PIL (v2.6): integer expected, got float -


first time i'm in forum. hope i'm specific enough. using imagechops inside pil, i'm trying multiply 2 images (both mode="l") same error message. i've looked everywhere couldn't find useful. i'd appreciate helpful ideas! relevant part of code attached.

    def point(self, f, searchimage, technique): # technique - inpaint or bicubic      dimx, dimy = searchimage.size      reader = csv.reader(f)     line in reader: #f.readlines():         coord = line         print coord         if searchimage.size[0] > float(coord[0])+95.5 , 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 , 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. pixel size of 14 micrometer results in             # 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 # avoid division 0         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         y in range(int(searchcrop.size[1])):              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 image          # pixels along cross axes value of 0         # --- 

the error message following:

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 image   pixels along cross axes 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 

the issue pil's crop method takes tuple of 4 integer values passing floats. should work:

box = tuple([int(math.floor(x)) x in box])


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -