Code Monkey home page Code Monkey logo

satellite_imagery_python's People

Contributors

acgeospatial avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

satellite_imagery_python's Issues

Looping function help

Hi @acgeospatial

I submitted an issue a few months ago querying how to run the analysis on multiple images at a time, I think I have managed to write a function to do this however when saving the cluster rasters the code overwrites the previous image. Do you know how this could be resolved? I have attached the code for the function below.

Many thanks,
Chloe

def k_means_segmentation(folder):
    images = []
    for filename in os.listdir(folder):
        img_ds = gdal.Open(os.path.join(folder,filename), gdal.GA_ReadOnly)
        ds = gdal.Open(os.path.join(folder, filename))
        band = ds.GetRasterBand(2)
        arr = band.ReadAsArray()
        [cols, rows] = arr.shape

        img = np.zeros((img_ds.RasterYSize, img_ds.RasterXSize, img_ds.RasterCount),
               gdal_array.GDALTypeCodeToNumericTypeCode(img_ds.GetRasterBand(1).DataType))
        for b in range(img.shape[2]):
            img[:, :, b] = img_ds.GetRasterBand(b + 1).ReadAsArray()
        images.append(img)
        
    for i in images:
        new_shape = (i.shape[0] * i.shape[1], i.shape[2])
        X = i[:, :, :8].reshape(new_shape)
        k_means = cluster.KMeans(n_clusters=5)
        k_means.fit(X)

        X_cluster = k_means.labels_
        X_cluster = X_cluster.reshape(i[:, :, 0].shape)
        
        format = "GTiff"
        driver = gdal.GetDriverByName(format)
        
        filename = "/testing_results/k_means.tif"
        outDataRaster = driver.Create(filename, rows, cols, 1, gdal.GDT_Byte)
        outDataRaster.SetGeoTransform(ds.GetGeoTransform())##sets same geotransform as input
        outDataRaster.SetProjection(ds.GetProjection())##sets same projection as input
        
        outDataRaster.GetRasterBand(1).WriteArray(X_cluster)
        
        outDataRaster.FlushCache() ## remove from memory
        del outDataRaster

Clustering_KMeans-Sentinel2.ipynb Query

Hi @acgeospatial thanks for this great repo!

I have a question regarding your Clustering_KMeans-Sentinel2.ipynb notebook - do you have any code to run the same clustering algorithm on many images at once as a sort of loop?
I would like to perform this classification on multiple images and having another method than doing each one individually would greatly reduce my workload!

Many thanks,
Chloe

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.