Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the deprecate skimage.io.imsave #18

Open
2320sharon opened this issue Jan 17, 2025 · 0 comments
Open

Remove the deprecate skimage.io.imsave #18

2320sharon opened this issue Jan 17, 2025 · 0 comments

Comments

@2320sharon
Copy link
Collaborator

update SDS_preprocess.py.zip

Skimage.io is deprecating imsave replace it with imagio.imwrite

Update of create_jpg

def create_jpg(
    im_ms: np.array,
    cloud_mask: np.array,
    date: str,
    satname: str,
    filepath: str,
    **kwargs,
) -> None:
    """
    Saves a .jpg file with the RGB image as well as the NIR and SWIR1 grayscale images.
    This functions can be modified to obtain different visualisations of the
    multispectral images.

    KV WRL 2018

    Arguments:
    -----------
    im_ms: np.array
        3D array containing the pansharpened/down-sampled bands (B,G,R,NIR,SWIR1)
    cloud_mask: np.array
        2D cloud mask with True where cloud pixels are
    date: str
        string containing the date at which the image was acquired
    satname: str
        name of the satellite mission (e.g., 'L5')
    filepath: str
        directory in which to save the images

    Returns:
    -----------
        Saves a .jpg image corresponding to the preprocessed satellite image

    """
    # rescale image intensity for display purposes
    im_RGB = rescale_image_intensity(im_ms[:, :, [2, 1, 0]], cloud_mask, 99.9)
    im_NIR = rescale_image_intensity(im_ms[:, :, 3], cloud_mask, 99.9)
    im_SWIR = rescale_image_intensity(im_ms[:, :, 4], cloud_mask, 99.9)
    # convert images to bytes so they can be saved
    im_RGB = img_as_ubyte(im_RGB)
    im_NIR = img_as_ubyte(im_NIR)
    im_SWIR = img_as_ubyte(im_SWIR)
    # Save each kind of image with skimage.io
    file_types = ["RGB", "SWIR", "NIR"]
    # create folders RGB, SWIR, and NIR to hold each type of image
    for ext in file_types:
        ext_filepath = filepath + os.sep + ext
        if not os.path.exists(ext_filepath):
            os.mkdir(ext_filepath)
        # location to save image ex. rgb image would be in sitename/RGB/sitename.jpg
        fname = os.path.join(ext_filepath, date + "_" + ext + "_" + satname + ".jpg")
        if ext == "RGB":
            imageio.imwrite(fname, im_RGB,quality=100)
        if ext == "SWIR":
            imageio.imwrite(fname, im_SWIR,quality=100)
        if ext == "NIR":
            imageio.imwrite(fname, im_NIR,quality=100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant