import matplotlib.pyplot as plt
import numpy as np
import os
# image processing libraries
import cv2
from PIL import Image
%matplotlib inline
# list all the images in the folder
os.listdir(r'C:\Users\lung_image_folder')
nrow = 2
ncol = 2
for img in image_folder:
# prepare for 2 x 2 layout for the figure
for i in range(ncol):
for j in range(nrow):
# check if the images end with jpg or jpeg or png
if img.endswith(".jpg") or img.endswith(".jpeg") or img.endswith("png"):
# ravel() flattens the 3 dimension data into 1 dimension data
# plot the histogram of the flattened array
plt.hist(img.ravel(),256,[0,256])
# save the images as pdf
plt.save( img, 'pdf')
plt.show()
У меня есть папка с данными изображений, загруженная с Kaggle - https://www.kaggle.com/datasets/andrewmvd/lung-and-colon-cancer-histopathological- images С помощью этой папки изображений я хочу [list] [*]сгладить каждый файл и построить гистограмму ( nrow = 2 и ncol = 2 на страницу)
[*]сохраните вывод гистограммы в виде PDF-файла с несколькими страницами
[/list] Мои мысли смотрите ниже [code]import matplotlib.pyplot as plt import numpy as np import os
# list all the images in the folder os.listdir(r'C:\Users\lung_image_folder')
nrow = 2 ncol = 2
for img in image_folder: # prepare for 2 x 2 layout for the figure for i in range(ncol): for j in range(nrow): # check if the images end with jpg or jpeg or png if img.endswith(".jpg") or img.endswith(".jpeg") or img.endswith("png"): # ravel() flattens the 3 dimension data into 1 dimension data # plot the histogram of the flattened array plt.hist(img.ravel(),256,[0,256]) # save the images as pdf plt.save( img, 'pdf')
plt.show()
[/code] [list] [*]поделитесь своим кодом с комментариями. [/list]