PySpark converting ImageBytes into numpy array – R of RGB are all 0

I have a code below.

image_df = session.read.format("image").load(image_path)

# Collect the image metadata
metadata = image_df.select("image.height", "image.width", "image.nChannels").first()
height = metadata["height"]
width = metadata["width"]
## I have to see why this portion gives 4 channels instead of 3.....
nChannels = metadata["nChannels"]

# Broadcast the height, width, and nChannels
height_broadcast = session.sparkContext.broadcast(height)
width_broadcast = session.sparkContext.broadcast(width)
nChannels_broadcast = session.sparkContext.broadcast(nChannels)

# Define a UDF to split the image array into separate R, G, B arrays
def split_rgb(data):
    
    # you need to access the broadcasted value by .value method
    height = height_broadcast.value
    width = width_broadcast.value
    nChannels = nChannels_broadcast.value
    # from buffer assumes that the input is byte data. dtype = the data type of the return
    image = np.frombuffer(data, dtype=np.uint8).reshape((height, width, nChannels), order = "C")   # numpy uses C order, so should be correct, but we must check....
    if nChannels == 4:  # Remove the alpha channel if present
        image = image[:, :, :3]
    r = image[:, :, 0].flatten().tolist()
    g = image[:, :, 1].flatten().tolist()
    b = image[:, :, 2].flatten().tolist()
    return r, g, b

split_rgb_udf = F.udf(lambda data: split_rgb(data), ArrayType(ArrayType(IntegerType())))

# Apply the UDF to the image DataFrame
rgb_df = image_df.withColumn("rgb", split_rgb_udf(F.col("image.data")))

# Select the RGB column and explode it into separate R, G, B columns
r_df = rgb_df.select(F.col("rgb")[0].alias("r"))
g_df = rgb_df.select(F.col("rgb")[1].alias("g"))
b_df = rgb_df.select(F.col("rgb")[2].alias("b"))

# this show section is commented out because i checked the outputs. 
# r_df.show(10)
# g_df.show(10)
# b_df.show(10)

# rdd.map: take each df and perform the lambda function inside and return. 
# later for computeSVD, the input must be RowMatrix. Thus need to take the df and put in as RowMatrix
r_rdd = RowMatrix(r_df.select('r').rdd.map(lambda row: DenseVector(row)))
g_rdd = RowMatrix(g_df.select('g').rdd.map(lambda row: DenseVector(row)))
b_rdd = RowMatrix(b_df.select('b').rdd.map(lambda row: DenseVector(row)))

# check if the image is imported correctly. 
print(r_rdd.rows.map(lambda row: sum(row.toArray())).sum())
print(g_rdd.rows.map(lambda row: sum(row.toArray())).sum())
print(b_rdd.rows.map(lambda row: sum(row.toArray())).sum())

Basically, it imports a png image file and then creates rdd of RowMatrix (I am going to do a SVD on them later). But the issue is, when I check if the values are imported correctly, in the print statements, I get 0 for the r_rdd sum, meaning that there is no R value. But the picture does have a lot of red in it.
I am guessing it went wrong in the np.frombuffer section where I convert image bytes to the numpy array, but I cannot seem to be able to fix it.

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