Eyeon:Script/Reference/Applications/Fuse/Classes/Image/MultiProcessPixels

From VFXPedia

Jump to: navigation, search

Contents


Summary

The MultiProcessPixels function will process every pixel within a specified range of a source image using the function provided as its last argument. This function is different than ProcessPixels in that the processing will be separated into multiple threads, to take better advantage of multiprocessor systems. The results will be written to a second destination image.


Usage

Image:MultiProcessPixels(function threadinitfunc, table globalenv, number x_start, number y_start, number x_end, number y_end [, Image srcimg1 [, ...]], function processfunc)

threadinitfunc (function, required)
This argument must be provided, but can be either nil. or a function. This can be used to provide a per-thread initialisation function, in case there is a need to calculate/remember something for each thread.
globalenv (table, required)
The MultiProcessPixels processfunc function does not have access to the variables in the global environment - it only has access to values passed to it in this table.
x_start, y_start, x_end, y_end (integer, required)
These four values are used to specify the range of pixels in the source image which will be affected by the process function. Usually x_start and y_start are set to 0, while x_end and y_end are set to the width and height of the image, respectively.
source_image (image, required )
An Image object which will provide the pixels used for the calculations. At least one image is required, but additional images can be specified as well.
process (function, required)
A function which will be executed for each pixel in the range specified by earlier arguments. The function will be passed three or more arguments in the form function(x, y, p1, ...) where x and y are the co-ordinates of the pixel and the remaining arguments are Pixel objects from each of the source images.


Example

The following example implements a very simple Gain using MultiProcessPixels. Note that this is not the recommended way to perform a Gain - see the Image:Gain function for a much faster approach.

FuRegisterClass("Gain", CT_Tool, {
	REGS_Category = "Fuses",
	REGS_OpIconString = "fGn",
	REGS_OpDescription = "Gain Fuse",
	})
 
function Create()
	InGain = self:AddInput("Gain", "Gain", {
		LINKID_DataType = "Number",
		INPID_InputControl = "SliderControl",
		INP_Default = 2.0,
		})			
 
	InImage = self:AddInput("Input", "Input", {
		LINKID_DataType = "Image",
		LINK_Main = 1,
		})
 
	OutImage = self:AddOutput("Output", "Output", {
		LINKID_DataType = "Image",
		LINK_Main = 1,
		})				
end
 
 
function Process(req) 
	local img = InImage:GetValue(req)
	local gain = InGain:GetValue(req).Value
	local method = InMethod:GetValue(req).Value
	
	local out = Image({IMG_Like = img})
	
	out:MultiProcessPixels(nil, { Gain = gain }, 0,0, img.Width, img.Height, img, 	function (x,y, p)
		p.R = p.R * Gain
		p.G = p.G * Gain
		p.B = p.B * Gain
		return p
		end)
	
	OutImage:Set(req, out)
end


Tips for MultiProcessPixels (edit)

  • It should be noted that x_end and y_end are not coordinates for the upper right corner of the area that will be processed but denote the width and height of that area. So, if you want to process a box from (100/100) to (150/150) the right way to call MultiProcessPixels would be:
out:MultiProcessPixels(nil, {}, 100, 100, 50, 50, source_img, process_function)