MCPcopy
hub / github.com/MrNothing/AI-Blocks / SendImageData

Function SendImageData

Sources/build_scripts/global_functions.py:42–67  ·  view source on GitHub ↗
(id, data, width=32, height=32, name="", rgba=False, flush=True, invert=False, offset=0, resize=[])

Source from the content-addressed store, hash-verified

40
41#data contains an array or normalized inputs (from 0 to 1)
42def SendImageData(id, data, width=32, height=32, name="", rgba=False, flush=True, invert=False, offset=0, resize=[]):
43 if EDITOR_MODE:
44 img = Image.new( 'RGBA', (width,height), "white")
45 pixels = img.load()
46
47 for i in range(len(data)): # for every pixel:
48 y = int(np.floor(i/width))
49 x = i-y*width
50 #print("coord: "+str(x)+"_"+str(y)+":"+str(data[i]))
51 if rgba:
52 pixel = max(0, data[i])
53 else:
54 pixel = [max(0, data[i]), max(0, data[i]), max(0, data[i]), 1]
55 if invert:
56 pixels[x,height-y-1] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly
57 else:
58 pixels[x,y] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly
59
60 if len(resize)>0:
61 img = img.resize((resize[0], resize[1]), Image.NEAREST)
62
63 tmpDir = tempfile.gettempdir()
64 imgPath = str(tmpDir)+"/"+name+"_out_"+str(id)+"_"+str(offset)+".png"
65 img.save(imgPath)
66
67 Log("img_data,"+str(id)+","+imgPath+","+name, flush)
68
69def SendAudioData(id, data, name, samplerate=4410, offset=0):
70 if EDITOR_MODE:

Callers 5

RunFunction · 0.85
RunFunction · 0.85
TrainFunction · 0.85
MNIST_loader.pyFile · 0.85
MINST_loader.pyFile · 0.85

Calls 3

LogFunction · 0.85
loadMethod · 0.80
saveMethod · 0.80

Tested by 1

RunFunction · 0.68