Vettorializzazione piano di volo

ciao a tutti, avrei bisogno di un consiglio e di una dritta.
ho questo raster già georiferito di un piano di volo dal quale vorrei estrarre strisciate e fotogrammi e magari anche un layer di punti con attributo il testo OCRizzato.

mi sapreste dare qualche consiglio?
l’operazione basica di vettorializzazione via gdal non dà alcun risultato sensato.

grazie mille

s.

Ciao, preciso a tutti che la procedura e lo script non sono farine del mio Sacco. In passato io semplicemente usavo OpenCV quando possibile, e delle volte tesseract ma con scarsi risultati, al punto che poi procedevo a mano o mediante Gimp, ma con Gimp perdevo le informazioni di georef, stessa cosa usando inkscape, poi ho chiesto a claude e mi ha prodotto uno script discreto che vi partecipo. Il trucco a quanto ne so è binarizzare l’immagine, inkscape riesce molto bene in questo ma per la georeferenziazione…non è il massimo. Io usavo per le mappe degli impianti solari, per la lettura di barcode…la logica è la stessa, a meno della segmentazione “SAM” per il ritaglio

Spero sia utile comunque in qualche modo

1 Like

Prova con Claude via server mcp. Sono riuscito a vettorializzare delle cose inimmaginabile.

grazie, ma sono proprio a digiuno.
riesci ad indicarmi qualche guida, tenendo conto che eventualmente ho abbonamento a OpenAI che uso in visual studio?

grazie mille

s.

Per piccoli task non hai bisogno di abbonamento a Claude (neanche io ce l’ho).

Segui questo video; se hai problemi scrvimi pure!

Ciao Ludovico,

mi hai incuriosito

vorrei capire un po’ meglio.

Il server mcp di qgis commette Claude con QGIS, ma QGIS ha sempre gli stessi strumenti, quindi quello che fa la differenza è ciò che chiedi (ovvero il prompt).

Che cosa gli chiederesti di fare nel caso dell’immagine di Stefano?

saluti

Ciao, ti quello che fa la differenza è il prompt: da quello che ho capito esegue codici python ad hoc quando non trova strumenti adeguati.

Questa è la conversazione di una vettorializzazione (come vedi ha prima valutato i tools nativi per poi passare a python):

riesci a vettorializzare l’immagine utilizzando come riferimento i diversi colori dell’immagine escludendo il bianco o simile?

I need to vectorize this image by classifying colors and excluding white tones—this is a raster-to-vector conversion task in QGIS. I should look for the execute_processing and execute_code tools since only a few are currently available.
Found tools
I’m planning to use PyQGIS with GDAL and NumPy to extract the raster data, classify pixels by color while filtering out white and near-white background pixels, then polygonize the result into vector features.
Writing code to inspect the raster…
Execute code
The raster is an ungeoreferenced PNG image with RGBA bands, so I can vectorize it in pixel space without worrying about coordinate systems. I need to sample the colors to understand what I’m working with—checking dominant colors, unique color counts, and identifying the pixel range for white or similar values. Then I’ll load the image and start analyzing it.
Execute code
The image is a photo with extensive color variation—38,327 unique colors from anti-aliasing and noise—showing tree canopies against a predominantly white background, which aligns with the project name referencing “chiome” (tree crowns in Italian). Given this complexity, a direct color-to-SVG conversion would be impractical, so I need to think about how to handle the massive color palette effectively.
The user wants to vectorize using different colors as reference points while excluding the white background, which suggests clustering the non-white pixels into a manageable number of color classes, then converting each class into polygons. I’ll mask out white and near-white pixels first (using a threshold where all RGB channels exceed ~235 and have minimal variation), then apply k-means clustering on the remaining pixels to group them into 6-8 representative color classes. After creating a classified raster with integer IDs for each cluster, I can use GDAL’s polygonize function to convert it into vector polygons, which I’ll save as a shapefile or GeoPackage for import into QGIS.
Looking at the actual color distribution, the white background pixels are essentially pure white (255,255,255) with minor JPEG artifacts, while the foreground greens have much lower blue channels (20-83 range), so a simple brightness threshold around 200 should cleanly separate them. I need to examine the histogram more carefully and check what’s happening in the intermediate range (118-200) to finalize the threshold.

Execute code
The white background is consistently around 64% of pixels across different thresholds, so I can safely filter it out by excluding pixels where the minimum channel value exceeds 200. That leaves about 36% of foreground pixels to cluster by color. I’ll use KMeans from sklearn to group these into a reasonable number of color classes, or fall back to manual quantization if the library isn’t available.
Execute code
I’ll skip the sklearn dependency and implement k-means clustering from scratch using numpy instead, which should be efficient enough for the 377k pixels. Since the image appears to be mostly olive-green shades varying in brightness—from dark tones around (53,69,20) to lighter ones near (204,209,92)—this likely represents different canopy density or shadow levels. I’m setting up a manual k-means algorithm with around 6 clusters to group the foreground pixels by their RGB values.
Once I have the cluster assignments, I’ll create a classified raster where the background stays as 0 (nodata) and foreground pixels get labeled 1 through k based on their cluster. Then I’ll write this as a GeoTIFF and use GDAL’s Polygonize function to convert each cluster class into vector polygons. Finally, I’ll load the resulting GeoPackage into QGIS with a categorized renderer styled by the representative centroid colors of each cluster, giving the user a clean legend and visualization.
Writing the complete script…

Execute code
The K-means clustering produced six classes that capture the gradient from dark to light olive green, likely reflecting variations in tree crown density and shadows. Now I’m converting this raster classification into vector polygons using GDAL’s polygonize function, then I’ll bring it into QGIS and apply categorized symbology based on the centroid colors of each class.
Execute code
I’m noticing the vectorization produced over 10,000 polygons, which is likely too noisy from per-pixel classification creating lots of small fragmented islands. I should apply a sieve filter to remove these tiny polygons and clean up the output.


Da: Totò Fiandaca noreply@discourse.osgeo.org
Inviato: Mercoledì, 22 Luglio, 2026 18:07
A: ludovicofrate@hotmail.it ludovicofrate@hotmail.it
Oggetto: [QGIS/QGIS-it-user] Vettorializzazione piano di volo

Someone replied to a topic you are Watching.


pigreco
July 22

Ciao Ludovico,

mi hai incuriosito

ludovico.frate:

Sono riuscito a vettorializzare delle cose inimmaginabile

vorrei capire un po’ meglio.

Il server mcp di qgis commette Claude con QGIS, ma QGIS ha sempre gli stessi strumenti, quindi quello che fa la differenza è ciò che chiedi (ovvero il prompt).

Che cosa gli chiederesti di fare nel caso dell’immagine di Stefano?

saluti

1 Like

Ciao Stefano,

hai risolto?

se sì, in che modo?

Oppure, come immagino, per questi casi cosi complicati è ancora impossibile ottenere un buon risultato.

Saluti

1 Like

@skampus , ci sono aggiornamenti?

Andrea