https://www.kaggle.com/datasets/andrewm ... hological- images
С помощью этой папки изображений я хочу
- сгладить каждый файл и построить гистограмму ( nrow = 2 и ncol = 2 на страницу)
- сохраните вывод гистограммы в виде PDF-файла с несколькими страницами
Код: Выделить всё
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()
- поделитесь своим кодом с комментариями.
Подробнее здесь: https://stackoverflow.com/questions/792 ... ened-image