ประกาศ : โปรเจ็กต์ที่ไม่ใช่เชิงพาณิชย์ทั้งหมดที่ลงทะเบียนเพื่อใช้ Earth Engine ก่อนวันที่
15 เมษายน 2025 ต้อง
ยืนยันการมีสิทธิ์ที่ไม่ใช่เชิงพาณิชย์ เพื่อรักษาสิทธิ์เข้าถึง หากคุณไม่ยืนยันภายในวันที่ 26 กันยายน 2025 ระบบอาจระงับสิทธิ์เข้าถึงของคุณ
การไล่ระดับสี
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
คุณสามารถคํานวณการไล่ระดับสีของแถบแต่ละแถบของรูปภาพได้ด้วย image.gradient()
เช่น โค้ดต่อไปนี้จะคํานวณขนาดและทิศทางของเส้นลาดของแถบภาพขาวดําของ Landsat 8
เครื่องมือแก้ไขโค้ด (JavaScript)
// Load a Landsat 8 image and select the panchromatic band.
var image = ee . Image ( 'LANDSAT/LC08/C02/T1/LC08_044034_20140318' ). select ( 'B8' );
// Compute the image gradient in the X and Y directions.
var xyGrad = image . gradient ();
// Compute the magnitude of the gradient.
var gradient = xyGrad . select ( 'x' ). pow ( 2 )
. add ( xyGrad . select ( 'y' ). pow ( 2 )). sqrt ();
// Compute the direction of the gradient.
var direction = xyGrad . select ( 'y' ). atan2 ( xyGrad . select ( 'x' ));
// Display the results.
Map . setCenter ( - 122.054 , 37.7295 , 10 );
Map . addLayer ( direction , { min : - 2 , max : 2 , format : 'png' }, 'direction' );
Map . addLayer ( gradient , { min : - 7 , max : 7 , format : 'png' }, 'gradient' );
โปรดทราบว่า gradient() จะแสดงผล 2 แถบ ได้แก่ การไล่ระดับสีในแนว X และการไล่ระดับสีในแนว Y ดังที่แสดงในตัวอย่าง คุณสามารถรวม 2 ทิศทางเข้าด้วยกันเพื่อรับขนาดและทิศทางของเส้นลาด ผลลัพธ์ควรมีลักษณะดังรูปที่ 1
รูปที่ 1 ระดับความลาดชันของภาพขาวดำสำหรับภาพ Landsat 8 เหนืออ่าวซานฟรานซิสโก รัฐแคลิฟอร์เนีย สหรัฐอเมริกา
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[],["The `image.gradient()` function computes the gradient of each image band, outputting X and Y-direction gradients. The example loads a Landsat 8 panchromatic band image, calculates the X and Y gradients, then determines the gradient's magnitude by combining the squared X and Y values and the gradient's direction using `atan2` function. Finally, it displays the gradient and its direction, centered on San Francisco. The image gradient magnitude is then illustrated.\n"]]