<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000'><font face="arial, helvetica, sans-serif" size="3">Potrei postare il piccolo programma che gira solo con immagini piu' piccole e si blocca con matrici grandi, in modo che possiate vedere direttamente. Ovviamente utilizzo numpy e per la verità la definizione di matrici anche di grandi dimensioni non genera problemi il blocco avviene quando si richiama gdal e le altre.</font><div style="color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 12pt; "><br></div><div style="color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 12pt; ">questo è il programmino:</div><div style="color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 12pt; "><br></div><div style="color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 12pt; "><br></div><div><div><font face="arial, helvetica, sans-serif">-----------------------------------------------------------------------------------------------------------------------------------------------------</font></div><div><font face="arial, helvetica, sans-serif">import skimage.graph as graph</font></div><div><font face="arial, helvetica, sans-serif">from skimage import filter</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">from skimage.morphology import watershed, is_local_maximum</font></div><div><font face="arial, helvetica, sans-serif">from scipy import ndimage</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">import os, numpy, sys, time,math,csv</font></div><div><font face="arial, helvetica, sans-serif">from osgeo import gdal, ogr</font></div><div><font face="arial, helvetica, sans-serif">from osgeo.gdalconst import *</font></div><div><font face="arial, helvetica, sans-serif">from math import *</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">from gdalconst import *</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">startTime = time.time()</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">os.chdir(r'c:\Users\lorenzo\lidar2')</font></div><div><font face="arial, helvetica, sans-serif"></font></div><div><font face="arial, helvetica, sans-serif">gdal.AllRegister()</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"># open the image</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">inDs1 = gdal.Open('conv_utm2m.tif',GA_ReadOnly)</font></div><div><font face="arial, helvetica, sans-serif">print 'legge immagine di convergenza'</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"># get image size</font></div><div><font face="arial, helvetica, sans-serif">rows = inDs1.RasterYSize</font></div><div><font face="arial, helvetica, sans-serif">cols = inDs1.RasterXSize</font></div><div><font face="arial, helvetica, sans-serif">bands = inDs1.RasterCount</font></div><div><font face="arial, helvetica, sans-serif">transform = inDs1.GetGeoTransform()</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">driver = gdal.GetDriverByName('GTiff')</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">outDs1 = driver.Create('conv_massimo.tif', cols, rows, 1, GDT_Int32)</font></div><div><font face="arial, helvetica, sans-serif">outDs2 = driver.Create('conv_chiome.tif', cols, rows, 1, GDT_Int32)</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">print 'righe', rows, 'colonne', cols, 'bande', bands</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">driver1 = inDs1.GetDriver()</font></div><div><font face="arial, helvetica, sans-serif"></font></div><div><font face="arial, helvetica, sans-serif"></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><span style="font-family: arial, helvetica, sans-serif; ">convergenza = numpy.ones((rows,cols),numpy.float)</span></div><div><font face="arial, helvetica, sans-serif">massimi =numpy.zeros((rows,cols),numpy.int)</font></div><div><font face="arial, helvetica, sans-serif">chiome = numpy.zeros((rows,cols),numpy.float)</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">inBand1 = inDs1.GetRasterBand(1)</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">print 'leggo convergenza'</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><span style="font-family: arial, helvetica, sans-serif; ">convergenza = inBand1.ReadAsArray(0,0,cols,rows).astype(numpy.float)</span></div><div><font face="arial, helvetica, sans-serif">print ' fatto ..'</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"></font></div><div><font face="arial, helvetica, sans-serif"></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">print ' ----- calcolo con algoritmo watershed -------'</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">print ' cerco il massimo locale sulla convergenza'</font></div><div><span style="font-family: arial, helvetica, sans-serif; ">massimi = is_local_maximum(convergenza)</span></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">print ' numero in modo progressimo i massimi'</font></div><div><font face="arial, helvetica, sans-serif">markers = ndimage.label(massimi)[0]</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">print ' allago le pozze i bacini........'</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">chiome = watershed(-convergenza, markers)</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">print 'lette tutte le righe'</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><span style="font-family: arial, helvetica, sans-serif; ">outBand1 = outDs1.GetRasterBand(1)</span><font face="arial, helvetica, sans-serif"></font></div><div><font face="arial, helvetica, sans-serif">outBand2 = outDs2.GetRasterBand(1)</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"># write the data</font></div><div><span style="font-family: arial, helvetica, sans-serif; ">outBand1.WriteArray(massimi, 0, 0)</span></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">outBand1.FlushCache()</font></div><div><font face="arial, helvetica, sans-serif">stats1 = outBand1.GetStatistics(0, 1)</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">outBand2.WriteArray(chiome, 0, 0)</font></div><div><font face="arial, helvetica, sans-serif">outBand2.FlushCache()</font></div><div><font face="arial, helvetica, sans-serif">stats2 = outBand2.GetStatistics(0, 1)</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><span style="font-family: arial, helvetica, sans-serif; ">outDs1.SetGeoTransform(transform)</span></div><div><font face="arial, helvetica, sans-serif">outDs2.SetGeoTransform(transform)</font></div><div><span style="font-family: arial, helvetica, sans-serif; ">outDs1 = None</span></div><div><font face="arial, helvetica, sans-serif">outDs2 = None</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><span style="font-family: arial, helvetica, sans-serif; ">inDs1 = None</span></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">print 'script took', time.time() - startTime, 'seconds to run'</font></div><br><hr id="zwchr" style="color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 12pt; "><div style="color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt; "><b>Da: </b>"Fabrizio Mancini" <mr.file@gmail.com><br><b>A: </b>"Discussioni generali sul linguaggio Python" <python@lists.python.it><br><b>Inviato: </b>Mercoledì, 6 giugno 2012 14:15:04<br><b>Oggetto: </b>Re: [Python] gestione della memoria<br><br>scusa forse per l'ovvietà, ma hai già provato a dare uno sguardo a numpy?<br><a href="http://numpy.scipy.org/" target="_blank">http://numpy.scipy.org/</a><br><br>Ciao Fabrizio<br>
<br>_______________________________________________<br>Python mailing list<br>Python@lists.python.it<br>http://lists.python.it/mailman/listinfo/python<br></div><br></div></div></body></html>