Skip to content

Instantly share code, notes, and snippets.

@ivogrig ivogrig/
Last active May 21, 2017

What would you like to do?
Loading an image clip and reading a pixel
import lxu
def loadImage(filepath, width, height):
Loads an image as clip and returns it's image interface object.
if not os.path.exists(filepath):
raise AttributeError("Path does not exist")
# Load image
sel_svc =
current_scene = sel_svc.current()
scn_svc = lx.service.Scene()
chan = current_scene.Channels(lx.symbol.s_ACTIONLAYER_EDIT, 0.0)
cout = lx.object.ChannelWrite(chan)
vclip = current_scene.ItemAdd(scn_svc.ItemTypeLookup(lx.symbol.sITYPE_VIDEOSTILL))
idx = vclip.ChannelLookup(lx.symbol.sICHAN_VIDEOSTILL_FILENAME)
cout.String(vclip, idx, filepath)
# Get to the image object
scene = vclip.Context()
channels = lx.object.ChannelRead (scene.Channels(None, 0.0) )
channel = vclip.ChannelLookup ("imageStack")
filter = lx.object.ImageFilter (channels.ValueObj (vclip, channel))
image = lxu.object.Image (filter.Generate (width, height, None))
return image
def readPixel(image, x, y):
Returns RGB or RGBA pixel values from an image
# Has Alpha?
numComponents = image.Components()
imageType = None
if numComponents == 1:
imageType = lx.symbol.iIMV_GREY
elif numComponents == 3:
imageType = lx.symbol.iIMV_RGB
elif numComponents == 4:
imageType = lx.symbol.iIMV_RGBA
# Read pixel
storage ='b', numComponents)
image.GetPixel(x, y, imageType, storage)
return storage.get()
img = loadImage('c:/temp/test.tga', 12, 12)
print readPixel(img, 0, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.