Closed redraw closed 1 year ago
Just testing. After reading the docs, tried to expose resized image pixels in a new Python Script Widget, so 30x30 x3 (RGB) = 2700 new features. But these aren't exactly embeddings, just RGB values.
import numpy as np
import os
from PIL import Image
from Orange.data import ContinuousVariable, Domain
column = in_data.domain['image']
assert 'origin' in column.attributes
rel_paths = in_data[:, column].metas.flatten()
full_paths = np.array([
os.path.join(column.attributes['origin'], path)
for path in rel_paths
])
pixels = []
for path in full_paths:
image = Image.open(path).convert('RGB').resize((30, 30))
values = np.array(image.getdata(), dtype=np.uint8).flatten() / 255.
pixels.append(values)
new_attrs = [ContinuousVariable.make('n{:d}'.format(d)) for d in range(len(values))]
for a in new_attrs:
a.attributes['hidden'] = True
new_domain = Domain(list(in_data.domain.attributes) + new_attrs, in_data.domain.class_vars, in_data.domain.metas)
table = in_data.transform(new_domain)
table[:, new_attrs] = np.array(pixels)
out_data = table
I guess I could try applying k-means or something? I haven't took a time to really think about it yet.
Hi. Sorry for the late reply. If I understand correctly you would like a widget that would visualize images such that images with similar colors would be close together? So some kind of image grid widget (already existing) but that features would not be embeddings but colors. Do I understand right?
Right, instead of embeddings, color/pixels data.
Image Analytics version
0.4.1
Orange version
3.24.1
This is not a bug, but a possible feature. It would be nice to visualize images by color. I was about to try with the Python Script widget, and sklearn or reading the Orange API doc, but maybe it would be helpful having a widget for that.
Maybe I am missing a way I can currently achieve that with the current widgets?