반응형
주피터 노트북을 사용하여 그리드에 여러 png을 표시하는 방법
나는 주피터 노트북과 같은 폴더에 있는 파일 이름 목록을 가지고 있다.
fnames =
노트북 출력 셀 내부의 그리드에 다음과 같은 이미지를 표시하려고 합니다.
- 행수
- 열 수
- 표시할 이미지 딤(픽셀 단위)(각 이미지에 대해 딤 표시)
다음을 수행하십시오.
import os
import numpy as np
import matplotlib.pyplot as plt
directory = "./Images/"
images = os.listdir(directory)
fig = plt.figure(figsize=(10, 10))
columns = 2
rows = np.ceil(len(images))
for x, i in enumerate(images):
path = os.path.join("./Images/",i)
img = plt.imread(path)
fig.add_subplot(rows, columns, x+1)
plt.imshow(img)
plt.show()
:
import os
import ipywidgets as widgets
from IPython.display import display
# Define a useful function
def get_image(f_path):
'''
Returns the image from a path
'''
img_labs = ['jpg','png']
if any(x in img_labs for x in f_path.split('.')):
file = os.path.join(folder,f_path)
image = open(file,'rb').read()
return image
# Do the actual work here
folder = 'Some Path to a Folder of Images'
files = os.listdir(folder)
images = [get_image(x) for x in files]
children = [widgets.Image(value = img) for img in images if str(type(img)) != '<class \'NoneType\'>']
labels = ['{}'.format(i) for i in range(len(children))]
# Customize your layout here:
box_layout = widgets.Layout(
display='flex',
flex_flow='column',
align_items='stretch',
border='solid',
width='50%')
# Create the widget
tab = widgets.Tab()
tab.children = children
# Label em'!
for i in range(len(children)):
tab.set_title(i,labels[i])
display(tab)
자세한 내용은 을 참조하십시오.
반응형
'개발하자' 카테고리의 다른 글
| 플러터 플러그인에서 수신기(브로드캐스트 수신기)를 어떻게 사용합니까? (0) | 2022.11.30 |
|---|---|
| 주피터 노트북에서 내 변수에 댓글을 달았지만 '변수가 정의되지 않은 오류' 대신 여전히 값 출력이 표시됩니다. (0) | 2022.11.29 |
| 유형 스크립트: 열거형의 문자열 리터럴 유니언 유형 (0) | 2022.11.28 |
| IPython 및 Jupyter Notebook에서 함수 호출 전 세미콜론을 사용하는 이상한 동작 (0) | 2022.11.27 |
| Flowter 디버거가 중단점에서 중지되지 않음 (0) | 2022.11.27 |