Replacing parts of satellite images#

In this notebook we load a satellite image and replace a part of it. Note: These kind of uses of generative artificial intelligence could be seen as scientific misconduct, e.g. if such images are further processed for analysis and usage of AI is not disclosed.

from skimage.io import imread
from image_utilities import replace
import stackview
import numpy as np

Image credits: modified Copernicus Sentinel data (2017), CC BY-SA 3.0 IGO. Source

image = imread("https://open.esa.int/files/2017/05/Bering_Sea-768x779.jpg")[:512, :512]
stackview.insight(image)
shape(512, 512, 3)
dtypeuint8
size768.0 kB
min0
max255

We define a binary mask of the region we would like to replace.

labels = np.zeros(image.shape[:2])
labels[100:300, 200:400] = 1

stackview.imshow(image, continue_drawing=True)
stackview.imshow(labels, alpha=0.6)
../_images/7a76d37a7ec1e0478989e640e5cb2b18fb956c0a0385fc28cc256d89b9730ab8.png

We replace the image, and also specify its size.

replaced_image = replace(image, labels)
stackview.imshow(replaced_image)
C:\structure\code\generative-ai-notebooks\docs\40_image_generation_openai\image_utilities.py:75: UserWarning: Using the replace function on scientific images could be seen as scientific misconduct. Handle this function with care.
  warn("Using the replace function on scientific images could be seen as scientific misconduct. Handle this function with care.")
../_images/2e45572888d39f0b2a9914c4288724cabbe7a0471e9154de461bf2863fde6df0.png
stackview.animate_curtain(image, replaced_image)
C:\Users\rober\miniforge3\envs\genai-gpu\Lib\site-packages\stackview\_animate.py:64: UserWarning: The image is quite large (> 10 MByte) and might not be properly shown in the notebook when rendered over the internet. Consider subsampling or cropping the image for visualization purposes.
  warnings.warn("The image is quite large (> 10 MByte) and might not be properly shown in the notebook when rendered over the internet. Consider subsampling or cropping the image for visualization purposes.")