Poor Quality Output When Pansharpening Multispectral Images Using Python

I’ve been trying to pansharpen some multispectral images using Python within a Docker environment, but the output image quality is very poor. The pansharpened image appears degraded, and I’m not sure what I might be doing wrong. I would appreciate any guidance or suggestions.

1- Locate the Panchromatic Image: I first search for the panchromatic file in the directory using the following function:

def find_panchro_images(directory):
    panchro_images = []
    other_images = []

    for root, _, files in os.walk(directory):
        for file in sorted(files):  # Sort the files before processing
            if file.lower().endswith(".tif"):
                file_path = os.path.join(root, file)

                try:
                    result = subprocess.run(
                        ["exiftool", "-BandName", file_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
                    )

                    if "Panchro" in result.stdout:
                        panchro_images.append(file_path)
                    else:
                        other_images.append(file_path)
                except Exception as e:
                    print(f"Error processing {file_path}: {e}")

    return panchro_images, other_images

2- Stack the Multispectral Channels Together: After identifying the multispectral bands, I stack them using this function:

def read_and_stack_bands(files):
    bands = []
    for file in files:
        with rasterio.open(file) as src:
            band = src.read(1)
            bands.append(band)

    stacked_image = np.dstack(bands)
    return stacked_image

3- Pansharpening: I then use the pansharpen function from the GitHub repository https://github.com/ThomasWangWeiHong/Simple-Pansharpening-Algorithms for the pansharpening process:

def pansharpen(m_files, pan, psh, R=3, G=2, B=1, NIR=4, method="esri", W=0.05):
    # Function implementation...

4- Finally, I execute the following script to apply the pansharpening:

if __name__ == "__main__":
    for folder in ["photo_1", "photo_2"]:
        folder_path = os.path.join(yasmina_dir, folder)
        output_folder = os.path.join(yasmina_dir, "output", folder)
        os.makedirs(output_folder, exist_ok=True)

        panchro_images, other_images = find_panchro_images(folder_path)

        print(f"nIn folder '{folder}':")
        if panchro_images:
            print("Panchromatic Image:")
            for image in panchro_images:
                print(image)

            print("Other Images:")
            for image in other_images:
                print(image)

            if len(panchro_images) == 1:
                other_images = sorted(other_images)[:4]  # Use only [B, G, R, NIR]

                output_image_name = os.path.basename(other_images[0]).replace("_1.tif", "_pansharpened.tif")
                psh_output_path = os.path.join(output_folder, output_image_name)

                pansharpen(other_images, panchro_images[0], psh_output_path)
            else:
                print("Multiple Panchromatic images found. Skipping pansharpening.")
        else:
            print("No Panchromatic images found. Skipping pansharpening.")

When I check the output image, it looks very bad (e.g., overly pixelated, image in grayscale). I’m not sure if the issue is due to the pansharpening method I’m using, a problem with how I’m reading the images, or something else.

Has anyone encountered a similar issue or can suggest what might be going wrong? I’m particularly interested in understanding if there’s a flaw in my image processing pipeline or if the problem lies with how the images are being rescaled or processed before pansharpening.

New contributor

feriel djelil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật