Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

A practical, end-to-end workflow for super-resolving a single image patch

You now understand what LDSR-S2 does internally. This page runs it, on a real Sentinel-2 scene, on a single patch, before later pages scale up to larger regions and add uncertainty estimation.


1. Motivation

This is the page where the previous three pages’ concepts become an actual enhanced image. Downloading, inspecting, and verifying the data before and after processing is not a formality; it is what confirms the output is genuinely usable in a GIS workflow, not just visually convincing.


2. Core idea

The workflow has a consistent shape: download and inspect the input imagery, visualize it, run super-resolution on a small patch, compare the result against the input, and verify the output’s georeferencing is correct before trusting it for anything further.


3. Workflow

A. Download and inspect the data

This is a Sentinel-2 Level-2A scene over Knoxville, Tennessee, with four 10-meter bands (red, green, blue, near-infrared) stored as uint16 surface reflectance values ranging from 0 to 10,000, where a value of 1,000 corresponds to 10% reflectance. This value range is standard for Sentinel-2 L2A products; do not mistake it for an already-8-bit image.

B. Visualize the RGB composite

The percentile stretch maps the 2nd and 98th percentile values to 0 and 1, a standard contrast-enhancement step that improves visual interpretability without letting a handful of extreme pixel values wash out the rest of the image.

C. Run single-patch super-resolution

window=(700, 1300, 128, 128) specifies (row_offset, col_offset, height, width) in pixel coordinates, extracting one 128-by-128 patch, LDSR-S2’s native input size, from the larger scene. sampling_steps=100 sets how many denoising steps the diffusion process runs; more steps generally improve quality up to a point, at a proportional cost in processing time.

D. Compare input and output

plot_sr_comparison() reads the low-resolution input, windowed to the same region, alongside the saved super-resolution output, letting you assess visually whether the enhancement reveals plausible additional structure, agricultural field boundaries, tree canopies, without needing to build the comparison plot yourself.

E. Verify the output’s georeferencing

Confirming the output CRS matches the input, and that the resolution is genuinely 2.5 meters, matters because it is what makes the enhanced output directly usable in GIS software, aligned with your other project data, rather than a plausible-looking image with no reliable spatial reference.


4. Python reactivation

with rio.open(s2_path) as src: is a context manager, the same pattern used for opening rasters throughout this course; it automatically closes the file when the block ends. src.read([1, 2, 3]) reads specific bands by their 1-based index into a NumPy array, and .transpose(1, 2, 0) reorders a channel-first array (bands, height, width) into the channel-last order (height, width, bands) that matplotlib’s imshow() expects.


5. Common pitfalls


6. Mini task

Without changing any code, predict what would happen to the output shape if you changed window=(700, 1300, 128, 128) to window=(700, 1300, 64, 64). Would this be a valid input for LDSR-S2 as described on the previous page?

Sample solution

A 64-by-64 window would not match LDSR-S2’s native 128-by-128 input size described on the previous page, so this would likely raise an error or require the function to handle a mismatched patch size in some other way, rather than simply producing a smaller, proportionally-scaled output. LDSR-S2 is built around a fixed 128x128 to 512x512 mapping; changing the input patch size is not simply a matter of requesting a different window size without also considering whether the model supports it.


7. Key takeaways