i have written python program takes x, y, c values (c being charge) particle detector , converts them grey scale heat map images. example of program produces below. should shown several clusters of grey-white areas on black background representing particle collisions screen. know because pixelman program use particle detector shows looks like, program lets without detector plugged in.
def heatmap(self): xlist=[] ylist=[] clist=[] directory = str(self.varrun.get()) if directory == "none selected" : tkmessagebox.showinfo("error", "no run selected") else: filename = askopenfilename(title = "choose new image import", initialdir=directory) if filename[-4:] != ".txt": tkmessagebox.showinfo("error", "you must select .txt image") else: open(filename,'r') f: reader=csv.reader(f,delimiter='\t') x, y, c in reader: xlist.append(int(x)) ylist.append(int(y)) clist.append(float(c)) #np.meshgrid(xlist,ylist) maxc = max(clist) array = np.zeros((256, 256)) in range (0, len(xlist)-1): rgbvalue = (float(clist[i]) / float(maxc)) * 255 array[ylist[i],xlist[i]] = rgbvalue array = sp.ndimage.zoom(array, 2, order=0) imagefromarray = image.fromarray(array, "1") imagefromarray.save(str(filename[:-4] + ".png")) newphoimg = imagetk.photoimage(imagefromarray) self.imageviewer.configure(image=newphoimg) self.imageviewer.image = newphoimg
the routine asks file , displays above. discovering why image not form appreciated. have checked xlist, ylist , clist correct values inserted them text file don't know goes wrong there. sample of input file is:
2 0 43.000000 3 0 65.000000 4 0 67.000000 5 0 33.000000 7 0 44.000000 8 0 102.000000 9 0 59.000000 10 0 31.000000 11 0 42.000000 12 0 29.000000 13 0 125.000000 14 0 115.000000 ... 247 255 38.000000
obviously continues way down y values of 255
now solved 2 images produced were:
as mentioned in comment, line
imagefromarray = image.fromarray(array, "1")
is suspect. converting floating point array 1-bit image (see http://effbot.org/imagingbook/concepts.htm#mode).
try changing line to
imagefromarray = image.fromarray(array).convert('l')
then imagefromarray
8-bit image can saved png file.
Comments
Post a Comment