Hi Perry, to clarify what I am doing - maybe the error lies in here:
* First I am building up a list of the corrected+rotated images * After that is done I am creating the figure * Then looping over every image, creating proper axes for each individual image and finally: > pylab.imshow(rotated_images[i],aspect='auto') > rotated_images[i]=[] > gc.collect(2) So I am trying to immediately delete the now obsolete image-data, by removing the reference and forcing garbage collection. No idea whether this is the proper/best way to do it ... but at least I hope my intention is clear :). Anyone an idea how to improve? Cheers, Gerd Perry Greenfield wrote: > Hi Gerd, > > It still hinges on how these are stitched together. E.g. if you created > the composite by using sliced and strided arrays, and keep those strided > arrays around, then the original images are still there. But it's hard > to know what's going on without the details. It sure sounds like the > original arrays are still around somewhere. > > Thanks, Perry > > On Dec 15, 2009, at 11:54 AM, Wellenreuther, Gerd wrote: > >> Well, I am trying to create an overlay, *one* picture showing all 34 >> images. So I am only trying to create a single figure. >> >> I just attached an example so you can get an idea (it was downsampled >> for mailing, the original picture has ca. 5500 x 6500 pixels). In the >> end, I just want to save the image to the disk, so I am using 'Agg' as >> the backend - hope this also saves me some memory. >> >> And about "old" images: I am always starting a completely new >> python-process for each stitching (one at a time). >> >> Cheers, Gerd >> >> Perry Greenfield wrote: >>> Are you clearing the figure after each image display? The figure >>> retains references to the image if you don't do a clf() and thus you >>> will eventually run out of memory, even if you delete the images >>> (they don't go away while matplotlib is using them). >>> Perry >>> On Dec 15, 2009, at 10:32 AM, Wellenreuther, Gerd wrote: >>>> Dear all, >>>> >>>> I am trying to write a script to be used with our microscope, stitching >>>> images of various magnifications together to yield a big picture of a >>>> sample. The preprocessing involves operations like rotating the picture >>>> etc., and finally those pictures are being plotted using imshow. >>>> >>>> Unfortunately, I am running into memory problems, e.g.: >>>> >>>>> C:\Python26\lib\site-packages\PIL\Image.py:1264: >>>>> DeprecationWarning: integer argument expected, got float >>>>> im = self.im.stretch(size, resample) >>>>> Traceback (most recent call last): >>>>> File "F:\Procs\Find_dendrites.py", line 1093, in <module> >>>>> >>>>> file_type="PNG",do_stitching=do_stitching,do_dendrite_finding=do_dendrite_finding,down_sizing_factor=48,dpi=600) >>>>> >>>>> >>>>> File "F:\Procs\Find_dendrites.py", line 1052, in process_images >>>>> scale,aspect_ratio,dpi,left,right,bottom,top) >>>>> File "F:\Procs\Find_dendrites.py", line 145, in stitch_images >>>>> pylab.draw() >>>>> File "C:\Python26\lib\site-packages\matplotlib\pyplot.py", line >>>>> 352, in draw >>>>> get_current_fig_manager().canvas.draw() >>>>> File >>>>> "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", >>>>> line 313, in draw >>>>> self.renderer = self.get_renderer() >>>>> File >>>>> "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", >>>>> line 324, in get_renderer >>>>> self.renderer = RendererAgg(w, h, self.figure.dpi) >>>>> File >>>>> "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", >>>>> line 59, in __init__ >>>>> self._renderer = _RendererAgg(int(width), int(height), dpi, >>>>> debug=False) >>>>> RuntimeError: Could not allocate memory for image >>>> >>>> or >>>> >>>>> Traceback (most recent call last): >>>>> File "F:\Procs\Find_dendrites.py", line 1093, in <module> >>>>> >>>>> file_type="PNG",do_stitching=do_stitching,do_dendrite_finding=do_dendrite_finding,down_sizing_factor=48,dpi=75) >>>>> >>>>> >>>>> File "F:\Procs\Find_dendrites.py", line 1052, in process_images >>>>> scale,aspect_ratio,dpi,left,right,bottom,top) >>>>> File "F:\Procs\Find_dendrites.py", line 142, in stitch_images >>>>> pylab.imshow(rotated_images[i],aspect='auto') >>>>> File "C:\Python26\lib\site-packages\matplotlib\pyplot.py", line >>>>> 2046, in imshow >>>>> ret = ax.imshow(X, cmap, norm, aspect, interpolation, alpha, >>>>> vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, >>>>> resample, url, **kwargs) >>>>> File "C:\Python26\lib\site-packages\matplotlib\axes.py", line 6275, >>>>> in imshow >>>>> im.set_data(X) >>>>> File "C:\Python26\lib\site-packages\matplotlib\image.py", line 291, >>>>> in set_data >>>>> self._A = pil_to_array(A) >>>>> File "C:\Python26\lib\site-packages\matplotlib\image.py", line 856, >>>>> in pil_to_array >>>>> x = toarray(im) >>>>> File "C:\Python26\lib\site-packages\matplotlib\image.py", line 831, >>>>> in toarray >>>>> x = np.fromstring(x_str,np.uint8) >>>>> MemoryError >>>> >>>> >>>> I already implemented some downscaling of the original images (ca. 3200 >>>> x 2400 pixels), to roughly match the figures dpi-setting. But this does >>>> not seem to be the only issue. The script does work for dpi of 600 or >>>> 150 for 11 individual images, yielding e.g. a 23 MB file with 600 dpi >>>> and 36 Megapixels. But it fails for e.g. 35 images even for 75 dpi. >>>> >>>> I was trying to throw away any unneccessary data using del + triggering >>>> the garbage collection, but this did not help beyond a certain point. >>>> Maybe somebody could tell me what kind of limitations there are using >>>> imshow to plot a lot of images together, and how to improve? >>>> >>>> Some more info: I am using Windows. Just by judging from the >>>> task-manager, the preprocessing is not the problem. But *plotting* the >>>> images using imshow seems to cause an increase of memory consumption of >>>> the task of 32-33 MB *each* time. Somewhere around a total of 1.3 - 1.5 >>>> Gigs the process dies ... >>>> >>>> Thanks in advance, >>>> >>>> Gerd >>>> -- >>>> Dr. Gerd Wellenreuther >>>> beamline scientist P06 "Hard X-Ray Micro/Nano-Probe" >>>> Petra III project >>>> HASYLAB at DESY >>>> Notkestr. 85 >>>> 22603 Hamburg >>>> >>>> Tel.: + 49 40 8998 5701 >>>> >>>> ------------------------------------------------------------------------------ >>>> >>>> >>>> Return on Information: >>>> Google Enterprise Search pays you back >>>> Get the facts. >>>> http://p.sf.net/sfu/google-dev2dev >>>> _______________________________________________ >>>> Matplotlib-users mailing list >>>> Matplotlib-users@lists.sourceforge.net >>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> -- >> Dr. Gerd Wellenreuther >> beamline scientist P06 "Hard X-Ray Micro/Nano-Probe" >> Petra III project >> HASYLAB at DESY >> Notkestr. 85 >> 22603 Hamburg >> >> Tel.: + 49 40 8998 5701 >> <Example_Microscope_Stitching.png> > -- Dr. Gerd Wellenreuther beamline scientist P06 "Hard X-Ray Micro/Nano-Probe" Petra III project HASYLAB at DESY Notkestr. 85 22603 Hamburg Tel.: + 49 40 8998 5701 ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users