Python 但我从未真正探索过。 def get_hsv_positions(image, positions): #hsv comes in hue (color of image), saturation and value that's supposed
但我从未真正探索过。Python 但我从未真正探索过。 def get_hsv_positions(image, positions): #hsv comes in hue (color of image), saturation and value that's supposed,python,python-imaging-library,Python,Python Imaging Library,但我从未真正探索过。 def get_hsv_positions(image, positions): #hsv comes in hue (color of image), saturation and value that's supposed to be how light or dark the color is hsv_image = image.convert('HSV') values = [] for pixel in positions:
def get_hsv_positions(image, positions):
#hsv comes in hue (color of image), saturation and value that's supposed to be how light or dark the color is
hsv_image = image.convert('HSV')
values = []
for pixel in positions:
values.append(hsv_image.getpixel(tuple(pixel)))
hues = set([x[0] for x in values])
hue_matches = []
width, height = image.size
img_width, img_height = 0,0
for _ in range(width * height):
if img_width == width:
img_height += 1
img_width = 0
pixel = hsv_image.getpixel((img_width, img_height))
if pixel[0] in hues:
hue_matches.append((img_width, img_height))
img_width += 1
return hue_matches
def get_color_range(request):
...
#this gets the x,y position on the image of interest to sample colors
cells = []
for item in selection:
pos = get_position(item['position']['left'], item['position']['top'], image.width, image.height, width, height)
item['position']['top'] = pos[1]
item['position']['left'] = pos[0]
scale_grid(item, width, height, image.width, image.height)
cells.extend(get_cells(item))
image = PILImage.open(image_url)
if hsv:
cells = get_hsv_positions(image, cells)
import numpy as np
hues = np.array(hues) # numpy it
blended_hues = np.concatenate([
hues + 1, hues + 2, ... # as many points out as you want
hues - 1, hues - 2, ...
])
all_hues = list(np.unique(np.concatenate([hues, blended_hues])))