import pandas as pd import matplotlib.pyplot as plt # Đọc file CSV # Thay "images.csv" bằng đường dẫn file của bạn df = pd.read_csv(r"D:\USTH\KLTN\cxr-vlm-data\mimic-cxr-2.0.0-metadata.csv") # Kiểm tra các cột cần thiết required_cols = ["Rows", "Columns"] for col in required_cols: if col not in df.columns: raise ValueError(f"Thiếu cột: {col}") # Tạo thêm cột diện tích ảnh df["TotalPixels"] = df["Rows"] * df["Columns"] # Thống kê cơ bản print("===== THỐNG KÊ KÍCH THƯỚC ẢNH =====") print(df[["Rows", "Columns", "TotalPixels"]].describe()) # Tỉ lệ khung hình df["AspectRatio"] = df["Columns"] / df["Rows"] print("\n===== THỐNG KÊ TỈ LỆ KHUNG HÌNH =====") print(df["AspectRatio"].describe()) # ------------------------- # Histogram chiều cao # ------------------------- plt.figure(figsize=(8, 5)) plt.hist(df["Rows"], bins=30) plt.xlabel("Rows (Height)") plt.ylabel("Number of Images") plt.title("Distribution of Image Heights") plt.grid(True) plt.show() # ------------------------- # Histogram chiều rộng # ------------------------- plt.figure(figsize=(8, 5)) plt.hist(df["Columns"], bins=30) plt.xlabel("Columns (Width)") plt.ylabel("Number of Images") plt.title("Distribution of Image Widths") plt.grid(True) plt.show() # ------------------------- # Histogram tổng pixel # ------------------------- plt.figure(figsize=(8, 5)) plt.hist(df["TotalPixels"], bins=30) plt.xlabel("Total Pixels") plt.ylabel("Number of Images") plt.title("Distribution of Image Sizes") plt.grid(True) plt.show() # ------------------------- # Scatter plot Width vs Height # ------------------------- plt.figure(figsize=(7, 7)) plt.scatter(df["Columns"], df["Rows"], alpha=0.5) plt.xlabel("Width (Columns)") plt.ylabel("Height (Rows)") plt.title("Image Resolution Distribution") plt.grid(True) plt.show() # ------------------------- # Top resolution phổ biến nhất # ------------------------- resolution_counts = ( df.groupby(["Rows", "Columns"]) .size() .reset_index(name="Count") .sort_values("Count", ascending=False) ) print("\n===== TOP RESOLUTION PHỔ BIẾN =====") print(resolution_counts.head(10))