ออบเจ็กต์รูปภาพคือชุดพิกเซลที่เชื่อมต่อกันซึ่งมีค่าจำนวนเต็มเดียวกัน ข้อมูลรูปภาพแบบหมวดหมู่ แบบกลุ่ม และบูลีนเหมาะสำหรับการวิเคราะห์ออบเจ็กต์
Earth Engine มีวิธีการติดป้ายกำกับแต่ละวัตถุด้วยรหัสที่ไม่ซ้ำกัน นับจำนวนพิกเซลที่ประกอบกันเป็นวัตถุ และคำนวณสถิติสำหรับค่าของพิกเซลที่ตัดกับวัตถุ
connectedComponents()
: ติดป้ายกำกับแต่ละออบเจ็กต์ด้วยตัวระบุที่ไม่ซ้ำกันconnectedPixelCount()
: คํานวณจํานวนพิกเซลในแต่ละออบเจ็กต์reduceConnectedComponents()
: คํานวณสถิติสําหรับพิกเซลในแต่ละออบเจ็กต์
ฮอตสปอตความร้อน
ส่วนต่อไปนี้แสดงตัวอย่างวิธีการที่อิงตามวัตถุซึ่งใช้กับอุณหภูมิพื้นผิวของ Landsat 8 โดยแต่ละส่วนจะอิงตามส่วนก่อนหน้า เรียกใช้สnippet ถัดไปเพื่อสร้างรูปภาพฐาน: ฮอตสปอตความร้อน (มากกว่า 303 องศาเคลวิน) สำหรับพื้นที่เล็กๆ ของซานฟรานซิสโก
เครื่องมือแก้ไขโค้ด (JavaScript)
// Make an area of interest geometry centered on San Francisco. var point = ee.Geometry.Point(-122.1899, 37.5010); var aoi = point.buffer(10000); // Import a Landsat 8 image, subset the thermal band, and clip to the // area of interest. var kelvin = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318') .select(['B10'], ['kelvin']) .clip(aoi); // Display the thermal band. Map.centerObject(point, 13); Map.addLayer(kelvin, {min: 288, max: 305}, 'Kelvin'); // Threshold the thermal band to set hot pixels as value 1, mask all else. var hotspots = kelvin.gt(303) .selfMask() .rename('hotspots'); // Display the thermal hotspots on the Map. Map.addLayer(hotspots, {palette: 'FF0000'}, 'Hotspots');
import ee import geemap.core as geemap
Colab (Python)
# Make an area of interest geometry centered on San Francisco. point = ee.Geometry.Point(-122.1899, 37.5010) aoi = point.buffer(10000) # Import a Landsat 8 image, subset the thermal band, and clip to the # area of interest. kelvin = ( ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318') .select(['B10'], ['kelvin']) .clip(aoi) ) # Threshold the thermal band to set hot pixels as value 1, mask all else. hotspots = kelvin.gt(303).selfMask().rename('hotspots') # Define a map centered on Redwood City, California. map_objects = geemap.Map(center=[37.5010, -122.1899], zoom=13) # Add the image layers to the map. map_objects.add_layer(kelvin, {'min': 288, 'max': 305}, 'Kelvin') map_objects.add_layer(hotspots, {'palette': 'FF0000'}, 'Hotspots')

รูปที่ 1 อุณหภูมิของภูมิภาคในซานฟรานซิสโก พิกเซลที่มีอุณหภูมิมากกว่า 303 องศาเคลวินจะแสดงเป็นสีแดง (จุดร้อน)
ติดป้ายกำกับออบเจ็กต์
การจัดป้ายกำกับวัตถุมักเป็นขั้นตอนแรกในการวิเคราะห์วัตถุ ในที่นี้ ระบบจะใช้ฟังก์ชัน connectedComponents()
เพื่อระบุออบเจ็กต์รูปภาพและกำหนดรหัสที่ไม่ซ้ำกันให้กับแต่ละรายการ โดยระบบจะกำหนดค่ารหัสแบบจำนวนเต็มเดียวกันให้กับพิกเซลทั้งหมดที่เป็นของออบเจ็กต์หนึ่งๆ ผลลัพธ์คือสำเนาของรูปภาพอินพุตที่มีแถบ "ป้ายกำกับ" เพิ่มเติมซึ่งเชื่อมโยงพิกเซลกับค่ารหัสออบเจ็กต์ตามการเชื่อมต่อของพิกเซลในแถบแรกของรูปภาพ
เครื่องมือแก้ไขโค้ด (JavaScript)
// Uniquely label the hotspot image objects. var objectId = hotspots.connectedComponents({ connectedness: ee.Kernel.plus(1), maxSize: 128 }); // Display the uniquely ID'ed objects to the Map. Map.addLayer(objectId.randomVisualizer(), null, 'Objects');
import ee import geemap.core as geemap
Colab (Python)
# Uniquely label the hotspot image objects. object_id = hotspots.connectedComponents( connectedness=ee.Kernel.plus(1), maxSize=128 ) # Add the uniquely ID'ed objects to the map. map_objects.add_layer(object_id.randomVisualizer(), None, 'Objects')
โปรดทราบว่าระบบตั้งค่าขนาดแพทช์สูงสุดไว้ที่ 128 พิกเซล ระบบจะปิดบังวัตถุที่ประกอบด้วยพิกเซลมากกว่า การเชื่อมต่อจะระบุโดยเคอร์เนล ee.Kernel.plus(1)
ซึ่งกำหนดการเชื่อมต่อแบบเพื่อนบ้าน 4 คน ใช้ ee.Kernel.square(1)
สำหรับเพื่อนบ้าน 8 คน

รูปที่ 2 วัตถุจุดร้อนทางความร้อนที่ติดป้ายกำกับและมีสไตล์ตามรหัสที่ไม่ซ้ำกัน
ขนาดของวัตถุ
จํานวนพิกเซล
คำนวณจำนวนพิกเซลที่ประกอบวัตถุโดยใช้วิธีconnectedPixelCount()
รูปภาพ การทราบจํานวนพิกเซลในวัตถุจะมีประโยชน์ในการมาสก์วัตถุตามขนาดและคำนวณพื้นที่ของวัตถุ ข้อมูลโค้ดต่อไปนี้ใช้ connectedPixelCount()
กับแถบ "labels" ของรูปภาพ objectId
ที่กําหนดไว้ในส่วนก่อนหน้า
เครื่องมือแก้ไขโค้ด (JavaScript)
// Compute the number of pixels in each object defined by the "labels" band. var objectSize = objectId.select('labels') .connectedPixelCount({ maxSize: 128, eightConnected: false }); // Display object pixel count to the Map. Map.addLayer(objectSize, null, 'Object n pixels');
import ee import geemap.core as geemap
Colab (Python)
# Compute the number of pixels in each object defined by the "labels" band. object_size = object_id.select('labels').connectedPixelCount( maxSize=128, eightConnected=False ) # Add the object pixel count to the map. map_objects.add_layer(object_size, None, 'Object n pixels')
connectedPixelCount()
จะแสดงผลสำเนาของรูปภาพอินพุต โดยแต่ละพิกเซลของแถบแต่ละแถบจะมีจำนวนเพื่อนบ้านที่เชื่อมต่อกันตามกฎการเชื่อมต่อเพื่อนบ้าน 4 หรือ 8 คน ซึ่งกำหนดโดยอาร์กิวเมนต์บูลีนซึ่งส่งไปยังพารามิเตอร์ eightConnected
โปรดทราบว่าระบบจะกำหนดการเชื่อมต่อแยกกันสำหรับแต่ละย่านของภาพอินพุต ในตัวอย่างนี้ มีการใช้รูปภาพย่านความถี่เดียว (objectId
) ที่แสดงรหัสออบเจ็กต์เป็นอินพุต ระบบจึงแสดงผลรูปภาพย่านความถี่เดียวที่มีย่านความถี่ "ป้ายกำกับ" (แสดงในรูปภาพอินพุต) แต่ตอนนี้ค่าจะแสดงจํานวนพิกเซลที่ประกอบขึ้นเป็นออบเจ็กต์ โดยพิกเซลทุกพิกเซลของออบเจ็กต์แต่ละรายการจะมีค่าจํานวนพิกเซลเดียวกัน

รูปที่ 3 วัตถุฮอตสปอตความร้อนที่ติดป้ายกำกับและจัดสไตล์ตามขนาด
พื้นที่
คำนวณพื้นที่ของวัตถุโดยการคูณพื้นที่ของพิกเซล 1 พิกเซลด้วยจํานวนพิกเซลที่ประกอบกันเป็นวัตถุ (กำหนดโดย connectedPixelCount()
) พื้นที่พิกเซลจะมาจากรูปภาพที่สร้างขึ้นจาก ee.Image.pixelArea()
เครื่องมือแก้ไขโค้ด (JavaScript)
// Get a pixel area image. var pixelArea = ee.Image.pixelArea(); // Multiply pixel area by the number of pixels in an object to calculate // the object area. The result is an image where each pixel // of an object relates the area of the object in m^2. var objectArea = objectSize.multiply(pixelArea); // Display object area to the Map. Map.addLayer(objectArea, {min: 0, max: 30000, palette: ['0000FF', 'FF00FF']}, 'Object area m^2');
import ee import geemap.core as geemap
Colab (Python)
# Get a pixel area image. pixel_area = ee.Image.pixelArea() # Multiply pixel area by the number of pixels in an object to calculate # the object area. The result is an image where each pixel # of an object relates the area of the object in m^2. object_area = object_size.multiply(pixel_area) # Add the object area to the map. map_objects.add_layer( object_area, {'min': 0, 'max': 30000, 'palette': ['0000FF', 'FF00FF']}, 'Object area m^2', )
ผลที่ได้คือรูปภาพที่พิกเซลแต่ละพิกเซลของวัตถุสัมพันธ์กับพื้นที่ของวัตถุเป็นตารางเมตร ในตัวอย่างนี้ รูปภาพ objectSize
มีแถบเดียว หากเป็นแถบหลายแถบ ระบบจะใช้การดำเนินการคูณกับแต่ละแถบของรูปภาพ
กรองวัตถุตามขนาด
คุณสามารถใช้ขนาดของวัตถุเป็นเงื่อนไขการมาสก์เพื่อมุ่งเน้นการวิเคราะห์ที่วัตถุขนาดหนึ่งๆ (เช่น มาสก์วัตถุที่เล็กเกินไป) ที่นี่จะใช้รูปภาพ objectArea
ที่คำนวณในขั้นตอนก่อนหน้าเป็นมาสก์เพื่อนำวัตถุที่มีพื้นที่น้อยกว่า 1 เฮกตาร์ออก
เครื่องมือแก้ไขโค้ด (JavaScript)
// Threshold the `objectArea` image to define a mask that will mask out // objects below a given size (1 hectare in this case). var areaMask = objectArea.gte(10000); // Update the mask of the `objectId` layer defined previously using the // minimum area mask just defined. objectId = objectId.updateMask(areaMask); Map.addLayer(objectId, null, 'Large hotspots');
import ee import geemap.core as geemap
Colab (Python)
# Threshold the `object_area` image to define a mask that will mask out # objects below a given size (1 hectare in this case). area_mask = object_area.gte(10000) # Update the mask of the `object_id` layer defined previously using the # minimum area mask just defined. object_id = object_id.updateMask(area_mask) map_objects.add_layer(object_id, None, 'Large hotspots')
ผลลัพธ์คือสำเนารูปภาพ objectId
ที่ปกปิดวัตถุที่มีพื้นที่น้อยกว่า 1 เฮกตาร์
![]() |
![]() |
---|---|
รูปที่ 4ก. วัตถุจุดร้อนทางความร้อนที่ติดป้ายกำกับและมีสไตล์ตามรหัสที่ไม่ซ้ำกัน | รูปที่ 4ข. ออบเจ็กต์จุดร้อนทางความร้อนที่กรองตามพื้นที่ขั้นต่ำ (1 เฮกตาร์) |
สถิติระดับโซน
เมธอด reduceConnectedComponents()
ใช้ตัวลดกับพิกเซลเพื่อประกอบออบเจ็กต์ที่ไม่ซ้ำกัน ข้อมูลโค้ดต่อไปนี้ใช้ค่านี้เพื่อคํานวณอุณหภูมิเฉลี่ยของวัตถุฮอตสปอต reduceConnectedComponents()
ต้องใช้รูปภาพอินพุตที่มีแถบ (หรือแถบ) ที่จะลด และแถบที่กําหนดป้ายกำกับวัตถุ ที่นี่มีการเพิ่มแถบรูปภาพ "ป้ายกำกับ" objectID
ลงในรูปภาพอุณหภูมิ kelvin
เพื่อสร้างรูปภาพอินพุตที่เหมาะสม
เครื่องมือแก้ไขโค้ด (JavaScript)
// Make a suitable image for `reduceConnectedComponents()` by adding a label // band to the `kelvin` temperature image. kelvin = kelvin.addBands(objectId.select('labels')); // Calculate the mean temperature per object defined by the previously added // "labels" band. var patchTemp = kelvin.reduceConnectedComponents({ reducer: ee.Reducer.mean(), labelBand: 'labels' }); // Display object mean temperature to the Map. Map.addLayer( patchTemp, {min: 303, max: 304, palette: ['yellow', 'red']}, 'Mean temperature' );
import ee import geemap.core as geemap
Colab (Python)
# Make a suitable image for `reduceConnectedComponents()` by adding a label # band to the `kelvin` temperature image. kelvin = kelvin.addBands(object_id.select('labels')) # Calculate the mean temperature per object defined by the previously added # "labels" band. patch_temp = kelvin.reduceConnectedComponents( reducer=ee.Reducer.mean(), labelBand='labels' ) # Add object mean temperature to the map and display it. map_objects.add_layer( patch_temp, {'min': 303, 'max': 304, 'palette': ['yellow', 'red']}, 'Mean temperature', ) display(map_objects)
ผลลัพธ์คือสำเนาของรูปภาพอินพุตที่ไม่มีแบนด์ที่ใช้กำหนดวัตถุ โดยค่าพิกเซลแสดงผลลัพธ์ของการลดต่อวัตถุต่อแบนด์

รูปที่ 5 พิกเซลของวัตถุฮอตสปอตความร้อนที่สรุปและจัดรูปแบบตามอุณหภูมิเฉลี่ย