Update helpers
This commit is contained in:
parent
c0b0dacd99
commit
f5c03db198
6 changed files with 140 additions and 4 deletions
2
editor/ploting/__init__.py
Normal file
2
editor/ploting/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
from .display_images import display_images
|
||||
from .plot_histograms import plot_histograms
|
||||
25
editor/ploting/display_images.py
Normal file
25
editor/ploting/display_images.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import matplotlib.pyplot as plt
|
||||
from typing import List
|
||||
from PIL.Image import Image
|
||||
from math import ceil
|
||||
|
||||
|
||||
def display_images(images: List[Image], titles: List[str], images_per_row: int = 3):
|
||||
fig, axes = plt.subplots(
|
||||
nrows=ceil(len(images) / images_per_row),
|
||||
ncols=min(images_per_row, len(images)),
|
||||
figsize=(12, 8),
|
||||
)
|
||||
|
||||
axes = axes.flatten()
|
||||
|
||||
for i, (title, image) in enumerate(zip(titles, images)):
|
||||
axes[i].imshow(image)
|
||||
axes[i].axis("off")
|
||||
axes[i].set_title(title)
|
||||
|
||||
for i in range(len(images), len(axes)):
|
||||
axes[i].axis("off")
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
51
editor/ploting/plot_histograms.py
Normal file
51
editor/ploting/plot_histograms.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
from plotly.subplots import make_subplots
|
||||
import plotly.graph_objects as go
|
||||
from math import ceil
|
||||
|
||||
|
||||
def plot_histograms(hists, histogram_per_row: int = 3):
|
||||
cols = min(histogram_per_row, len(hists))
|
||||
fig = make_subplots(
|
||||
rows=ceil(len(hists) / histogram_per_row),
|
||||
cols=cols,
|
||||
specs=[[{"type": "scatter3d"} for _ in range(cols)] for _ in range(1)],
|
||||
)
|
||||
for i, hist in enumerate(hists, start=1):
|
||||
fig.add_trace(_get_3d_scatter_plot_from_histogram(hist), row=1, col=i)
|
||||
|
||||
fig.update_layout(
|
||||
width=1200,
|
||||
height=600,
|
||||
scene1=dict(xaxis_title="R", yaxis_title="G", zaxis_title="B"),
|
||||
scene2=dict(xaxis_title="R", yaxis_title="G", zaxis_title="B"),
|
||||
)
|
||||
fig.show()
|
||||
|
||||
|
||||
def _get_3d_scatter_plot_from_histogram(hist):
|
||||
x, y, z, marker_size = [], [], [], []
|
||||
bins = len(hist)
|
||||
|
||||
for i, row in enumerate(hist):
|
||||
for j, col in enumerate(row):
|
||||
for k, value in enumerate(col):
|
||||
if value > 0:
|
||||
x.append(i)
|
||||
y.append(j)
|
||||
z.append(k)
|
||||
marker_size.append(value)
|
||||
|
||||
return go.Scatter3d(
|
||||
x=x,
|
||||
y=y,
|
||||
z=z,
|
||||
mode="markers",
|
||||
marker=dict(
|
||||
size=[min(20, ms * 10000) for ms in marker_size],
|
||||
color=[
|
||||
f"rgb({xi*256/bins},{yi*256/bins},{zi*256/bins})"
|
||||
for xi, yi, zi in zip(x, y, z)
|
||||
],
|
||||
opacity=0.8,
|
||||
),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue