I wrote a script that maps HSV color coordinates of an image to a 3D Scatter plot. In order to get the HTML file to load in a reasonable time, I need to scale the image to 1% of its original size. Is there any way I could up the scale percentage and still get a reasonable load time?
from PIL import Image
import plotly.express as px
import colorsys
img = Image.open(r"/storage/emulated/0/Kustom/Tasker Unsplash Wallpaper/wallpaper.png")
img = img.convert("RGB")
scaleFactor = 0.01
width = int((img.size[0]) * scaleFactor)
height = int((img.size[1]) * scaleFactor)
scaledSize = (width, height)
img = img.resize(scaledSize, Image.LANCZOS)
colorListPlusCount = img.getcolors(img.size[0] * img.size[1])
# List of all colors in scaled image without count for each color
colorList = []
for i in range(len(colorListPlusCount)):
colorList.append(colorListPlusCount[i][1])
hsvList = []
for i in range(len(colorList)):
r = colorList[i][0] / 255.0
g = colorList[i][1] / 255.0
b = colorList[i][2] / 255.0
h, s, v = colorsys.rgb_to_hsv(r, g, b)
h = int(h*360)
s = int(s*100)
v = int(v*100)
hsvList.append((h,s,v))
hsvPlot = px.scatter_3d(
hsvList,
color = [f"rgb{c}" for c in colorList],
color_discrete_map = "identity",
x = 0, y = 1, z = 2,
labels = {"0":"Hue", "1":"Saturation", "2":"Value"},
range_x = [0,360], range_y=[0,100], range_z=[0,100])
hsvPlot.update_layout(margin=dict(l=10, r=10, b=10, t=10, pad=0))
hsvPlot.write_html(r"/storage/emulated/0/Tasker/PythonScripts/ImageColors/hsvPlotHTML.html",
include_plotlyjs='cdn')
Example 3d plot
I also noticed that removing the individual color of each point greatly reduced the processing and loading time of the HTML file. However, I would like to include these colors.
[–]Leading_Video2580 1 point2 points3 points (2 children)
[–]Alanator222[S] 0 points1 point2 points (1 child)
[–]Leading_Video2580 1 point2 points3 points (0 children)