0

How can I get a smoother line?

var image = ee.Image('users/cananhamzaolu/KIYI500')
var roi = ee.Geometry.Polygon = ([
    [31.577169138841125, 41.30667497201365],
    [33.33498163884112, 41.30667497201365],
    [33.33498163884112, 41.91451886804031],
    [31.577169138841125, 41.91451886804031],
    [31.577169138841125, 41.30667497201365]
])
var clip = image.clip(roi)
Map.addLayer(clip, {
    'min': 0,
    'max': 1
}, 'image', false)
var canny = ee.Algorithms.CannyEdgeDetector({
    image: clip,
    threshold: 0,
    sigma: 1
});
Map.addLayer(canny, {
    'min': 0,
    'max': 1
}, 'canny')
4
  • Pease explain your problem and steps you took to try and solve it, and include your actual code rather than a link. Commented Jan 26, 2022 at 18:10
  • thank you so much,I edited
    – CHH
    Commented Jan 26, 2022 at 20:32
  • I guess you want to do "vector-simplification-like" simplification. You can make a line (vector) from raster, simplify the line, convert to raster. But I don't know how to do in GEE. Commented Jan 26, 2022 at 23:38
  • @KadirŞahbaz yes, I converted it to vector but I run across scale problem. My interest of region is huge and When I determined scale as 30, I got a problem. When I determined the scale as 1000 the lines seems weird
    – CHH
    Commented Jan 27, 2022 at 8:48

1 Answer 1

0

As @kadir suggested you can use a reduceToVector similar to this:

var toVec = canny.select('b1').int().reduceToVectors({
  geometry: roi,
  crs: image.projection(),
  scale: 100,
  geometryType: 'polygon',
  eightConnected: false,
  labelProperty: 'zone',

  
})

Be aware that this creates a vector around your pixels, so it will not be a single line representing the pixels. You'll have to smooth that with the .simplify() functionallity.

https://code.earthengine.google.com/3a15a4a9d9eefb7741636d3eebbf12fc

5
  • yes,I got like image,I will try to apply simplify function
    – CHH
    Commented Jan 27, 2022 at 8:51
  • glad it worked, if you believe this answered your question it might be helpful to others as well if you accept it.
    – Jobbo90
    Commented Jan 27, 2022 at 16:08
  • can i edit my line without converting it to vector? Because when I convert the line to vector the line does not represent the shore boundary correctly
    – CHH
    Commented Jan 28, 2022 at 8:35
  • Yes you can, but not sure what you want? Perhaps ask a separate question for that because getting your line to 'represent' the shore boundary is a whole other story
    – Jobbo90
    Commented Jan 28, 2022 at 11:49
  • yeah you are right :)
    – CHH
    Commented Jan 28, 2022 at 15:44

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.