I have a land cover image and I segmented it. Since the images are large in size, I am uploading only a part of them. here is the original image's part :enter image description here

here is the corresponding segmented image: enter image description here

I used K-means clustering algorithm to achieve segmentation. Now I want to extract different regions marked with same intensity in the segmented image so as to classify it for the land cover. Is it possible to extract different regions directly from the segmented image (if possible in the form of polygons) to classify them.

Please help me with a source/link or a way on how to do it or atleast begin with it. P.s I work on Python

  • 1
    To be able to help you we really need to know more about the nature of the segmented image. Can you be more specific or maybe upload a subset of it?
    – Kersten
    Jul 6, 2015 at 19:41
  • @Kersten I have edited the question. See if you are able to comprehend now.
    – rach
    Jul 7, 2015 at 7:07
  • From these JPGs I am still not able to induce the type of your data: Are they labelled rasters or just plain GeoTiffs where each pixel has a value representing a discrete class? In the last case you'd just need to polygonize your raster.
    – Kersten
    Jul 7, 2015 at 18:17
  • It is just a plain tiff where each pixel has a fixed intensity values.
    – rach
    Jul 8, 2015 at 16:26
  • 1
    Then your solution is as easy as polygonizing a raster band.
    – Kersten
    Jul 8, 2015 at 18:56

1 Answer 1


How are the segments defined? Are they labeled raster? If so you could use GDAL binaries to export each label to a separate binary raster and multiply the binary raster to the source to obtain the result wanted.

Say you want to transform label 12 , then you would do something like gdal_calc -A [LabelRasterPath] -B [SourceRasterPath] --calc="(A=12)*B" --NoDataValue=0

You can make use of a batch file to process everything.

Another option, if you want to stick with python numpy is to use masked array and define the mask as labeledArray==12 for example.

Please let me know if you need further assistance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.