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)
|
|
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)

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.")

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.")