Skip to content

Commit

Permalink
Merge pull request #44 from TUW-GEO/03_review_dfesta
Browse files Browse the repository at this point in the history
Notobeooks 07 code and concepts correction
  • Loading branch information
MartinSchobben authored Dec 2, 2024
2 parents 3effcd5 + e1cec85 commit 6f908f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions unit_03/07_homework_exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's build up the lee filter function that we already saw in the in-class notebook. Would you be able to describe the mathematical operations involved in the function?"
"Let's build up the Lee filter function that we already saw in the in-class notebook:"
]
},
{
Expand Down Expand Up @@ -100,7 +100,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Apply your function and compute the Lee filter for at least two different kernel sizes."
"Apply your function and compute the Lee filter for at least two different kernel sizes (size number must be odd)."
]
},
{
Expand Down Expand Up @@ -148,10 +148,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"- [ ] By increasing the kernel size, the resolution of the image increases.\n",
"- [ ] By decreasing the kernel size, speckle noise is reduced.\n",
"- [ ] Increasing or decreasing the kernel size does not really affect speckle noise.\n",
"- [ ] By increasing the kernel size, speckle noise is reduced."
"- [ ] The larger the kernel size, the lower the resolution of the resulting image.\n",
"- [ ] The smaller the kernel size, the more speckle noise is removed.\n",
"- [ ] The choice of the kernel size has no impact on the speckle noise removal.\n",
"- [ ] The larger the kernel size, the more speckle noise is removed."
]
}
],
Expand Down
36 changes: 18 additions & 18 deletions unit_03/07_in_class_exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"\n",
"This notebook will provide an empirical demonstration of speckle - how it originates, how it visually and statistically looks like, and some of the most common approaches to filter it.\n",
"\n",
"Speckle is defined as a kind of noise that affects all radar images. Given the multiple scattering contributions originating from the various elementary objects present within a resolution cell, the resulting backscatter signal can be described as a random constructive and destructive interference of wavelets. As a consequence, speckle is the reason why a granular pattern normally affects SAR images, making it more challenging to interpret and analyse them. "
"Speckle is defined as a kind of noise that affects all radar images. Given the multiple scattering contributions originating from the various elementary objects present within a resolution cell, the resulting backscatter signal can be described as a random constructive and destructive interference of wavelets. As a consequence, speckle is the reason why a granular pattern normally affects SAR images, making it more challenging to interpret and analyse them.\n",
"\n",
"![](../assets/images/speckle_effect.png){width=300}\n",
"\n",
"*Credits: ESRI*"
]
},
{
Expand Down Expand Up @@ -42,7 +46,7 @@
"\n",
"We should ideally have a uniform discrete **sigma naught** $\\sigma^0$ value, given that the cornfield pixel is the only individual contributor.\n",
"\n",
"However, since we already learned from the previous notebooks that a pixel's ground size can be in the order of tens of meters (i.e., 10 meters for Sentinel-1), we can imagine that many sub-pixel objects (e.g., rocks, trees,...) contribute to the global backscattered information.\n",
"However, since we already learned from the previous notebooks that a pixel's ground size can be in the order of tens of meters (i.e., 10 meters for Sentinel-1), we can imagine that different distributed targets in the scene contribute to the global backscattered information.\n",
"\n",
"Let´s replicate this behavior with an ideal uniform area constituted by 100 pixels and then by adding 30% of speckle."
]
Expand Down Expand Up @@ -72,7 +76,7 @@
"# Initialize speckled data as the same as the ideal data\n",
"speckled_data_linear = ideal_data_linear.copy()\n",
"\n",
"speckle_noise = np.random.rayleigh(scale=1.0, size=num_speckled_pixels)\n",
"speckle_noise = np.random.gumbel(scale=1.0, size=num_speckled_pixels)\n",
"speckled_data_linear.ravel()[speckled_indices] *= (\n",
" speckle_noise # Add speckle to the selected pixels\n",
")\n",
Expand Down Expand Up @@ -132,15 +136,9 @@
"source": [
"*Figure 1: Synthetic data that emulates speckles in microwave backscattering*\n",
"\n",
"We can imagine that the second plot represents one pixel of cornfield from a real SAR acquisition, while the first plot represents an ideal uniform pixel of cornfield (no speckle). The introduction of a simulated 30% speckle noise could be related to the presence of small objects of any sort present in the scene, which would cause a pixel-to-pixel variation in terms of intensity.\n",
"Backscatter depends on:\n",
"We can imagine that the second plot represents a real SAR acquisition over a cornfield, while the first plot represents an ideal uniform SAR image over a cornfield land (no speckle). The introduction of a simulated 30% speckle noise could be related to the presence of distributed scatterers of any sort present in the scene, which would cause a pixel-to-pixel variation in terms of intensity.\n",
"\n",
"- Dielectric properties of an object,\n",
"- Frequency of electromagnetic signal,\n",
"- Angle of acquisition,\n",
"- Cross-section of ground object, etc.\n",
"\n",
"All these random contributions (such as the wind) would result in a different speckle pattern each time a SAR scene is acquired over the same area. Many subpixel contributors build up a complex scattered pattern in any SAR image, making it erroneous to rely on a single pixel intensity for making reliable image analysis. In order to enhance the degree of usability of a SAR image, several techniques have been put in place to mitigate speckle.\n",
"All the random contributions (such as the wind) would result in a different speckle pattern each time a SAR scene is acquired over the same area. Many subpixel contributors build up a complex scattered pattern in any SAR image, making it erroneous to rely on a single pixel intensity for making reliable image analysis. In order to enhance the degree of usability of a SAR image, several techniques have been put in place to mitigate speckle.\n",
"We will now show two of the most common approaches: the temporal and the spatial filter.\n",
"\n",
"## Lake Neusiedl data\n",
Expand Down Expand Up @@ -325,7 +323,7 @@
"\n",
"We can mitigate speckle (it is impossible to remove it completely) by following approaches such as:\n",
"- spatial filtering - taking mean backscatter value over the same land cover, or\n",
"- temporal filtering - focusing on a small area or even one pixel, but averaging it over some time period.\n",
"- temporal filtering - taking the average backscatter value over some time period.\n",
"\n",
"Either way, one pixel is never representative of ground truth! Therefore we need to look at samples and distributions."
]
Expand All @@ -336,13 +334,15 @@
"source": [
"## Spatial filtering\n",
"\n",
"We first introduce a common spatial filter. The Lee filter is an adaptive speckle filter. It follows three assumptions:\n",
"We first introduce a common spatial filter. The Lee filter is an adaptive speckle filter. The filter works using a kernel window with a configurable size, which refers to the dimensions of the neighborhood over which the filter operates. The kernel slides across the data, applying the smoothing operation at each pixel position of the image. It follows three assumptions:\n",
"\n",
"1) SAR speckle is modeled as a multiplicative noise - the brighter the area the noisier the data.\n",
"2) The noise and the signal are statistically independent of each other.\n",
"3) The sample mean and sample variance of a pixel is equal to its local mean and local variance.\n",
"\n",
"Let's build up a function for applying a Lee filter with a kernel size of 7 (do not forget to switch back to linear units before doing this computation and to dB after it):"
"This approach comes with some limitations: it reduces the spatial resolution of the SAR image.\n",
"\n",
"Let's build up a function for applying a Lee filter with a kernel window size of 7 (do not forget to switch back to linear units before doing this computation and to dB after it):"
]
},
{
Expand All @@ -357,7 +357,7 @@
" raster: ndarray\n",
" 2D array representing the noisy image (e.g., radar image with speckle)\n",
" size: int\n",
" Window size for the filter (must be odd, default is 7)\n",
" Size of the kernel window for the filter (must be odd, default is 7)\n",
"\n",
" Returns:\n",
" filtered_image (ndarray): The filtered image with reduced speckle noise\n",
Expand All @@ -366,7 +366,7 @@
" raster = np.nan_to_num(raster)\n",
" raster = 10 ** (raster / 10)\n",
"\n",
" # Mean and variance over local window\n",
" # Mean and variance over local kernel window\n",
" mean_window = uniform_filter(raster, size=size)\n",
" mean_sq_window = uniform_filter(raster**2, size=size)\n",
" variance_window = mean_sq_window - mean_window**2\n",
Expand Down Expand Up @@ -397,7 +397,7 @@
"\n",
"## Temporal filtering\n",
"\n",
"Temporal filtering would involve taking the median of all previous (past) observations for each pixel. This approach comes with severe limitations since it takes out the content-rich information tied to the temporal variability of backscatter."
"Temporal filtering would involve taking the average of all previous (past) observations for each pixel. This approach comes with some limitations: it takes out the content-rich information tied to the temporal variability of backscatter."
]
},
{
Expand All @@ -417,7 +417,7 @@
" filtered_image (ndarray): The filtered image with reduced speckle noise\n",
" \"\"\"\n",
"\n",
" return raster.median(\"time\")\n"
" return raster.mean(\"time\")\n"
]
},
{
Expand Down

0 comments on commit 6f908f6

Please sign in to comment.