Cannot plot a big tif image using pyplot

import streamlit as st
import rasterio
from rasterio.plot import show
from tempfile import NamedTemporaryFile
import os
import matplotlib.pyplot as plt
import pyproj
import plotly.express as px
from PIL import Image
Image.MAX_IMAGE_PIXELS = None

uploaded_file = st.file_uploader(“Upload TIFF file”, type=[“tif”, “tiff”])
with st.spinner(“Processing…”):
if uploaded_file is not None:
# Create a temporary file to save the uploaded file
with NamedTemporaryFile(delete=False, suffix=“.tif”) as tmp:
tmp.write(uploaded_file.getvalue())
tmp_path = tmp.name

    with rasterio.open(tmp_path) as src:
        im = Image.open(tmp_path)
        st.write(f"Number of bands: {src.count}")
        st.write(f"Width: {src.width}")
        st.write(f"Height: {src.height}")
        if src.crs:
            st.write(f"CRS: {src.crs}")
            st.write("Georeferenced: Yes")
        else:
            st.write("Georeferenced: No")

        # Check if the raster has geotransform information
        if src.transform:
            st.write(f"Transform: {src.transform}")
        else:
            st.write("Transform: Not available")
        # x = st.number_input("pixel x")
        # x = int(x)
        # y = st.number_input('pixel y')
        # y = int(y)
        # # Define the projection objects for EPSG:32618 and WGS84
        # proj_UTM = pyproj.Proj(init='epsg:32618')  # UTM zone 18N
        # proj_WGS84 = pyproj.Proj(init='epsg:4326')  # WGS84
        # if x and y:
        #     cx, cy = src.xy(x,y) 
        #     st.write(f"{cx}, {cy}")
        #     lon, lat = pyproj.transform(proj_UTM, proj_WGS84, cx, cy)
        #     st.write(f"Latitude, Longitude => {lat}, {lon}")
        #     st.write(f"You entered => {x}, {y}")
        st.subheader("Visualizing the TIFF file")
        
        fig = px.imshow(im)
        st.plotly_chart(fig) 


    # Clean up the temporary file
    os.unlink(tmp_path)

This code is giving me an error : MessageSizeError: Data of size 5013.7 MB exceeds the message size limit of 200.0 MB.
image size is 46798 by 55445 and it is 1.3 GB

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.