get a function that maps index-coordinates of image0-coordinate-space to the index-coordinates of image1-coordinate-space
note that if you're mapping lots of indexes using Array.map, it would be 40-times faster to use the lambdacalc.vectorize1 function instead
Example
// suppose you have an RGBA image data buffer of `width = 100`, `height = 50`, `channels = 4` <br> // and you have an array of 6 pixel indexes: `idx0 = [1040, 1044, 1048, 1140, 1144, 1148]` <br> // and you want to convert these indexes to that of an LA image data buffer of `width = 10`, `height = 10`, `channels = 2`, `x = 5`, `y = 10` // then: const coords0 = {x:0, y:0, width:100, height:50, channels:4}, coords1 = {x:5, y:10, width:10, height:10, channels:2}, coords0_to_coords1 = coordinateTransformer(coords0, coords1), idx0 = [4040, 4044, 4048, 4440, 4444, 4448], idx1 = idx0.map(coords0_to_coords1) // [10, 12, 14, 30, 32, 34]
Derivation
/** the equation for mask_intervals can be easily derived as follows:
p0 = px of data, y0 = y-coords of pixel in data, x0 = x-coords of pixel in data, w0 = width of data, c0 = channels of data
p1 = px of mask, y1 = y-coords of pixel in mask, x1 = x-coords of pixel in mask, w1 = width of mask, c1 = channels of mask
y = y-coords of mask's rect, x = x-coords of mask's rect
(i0: number & coord0) => i1 as number & coord1 a function that takes in an integer index from coordinate space coords0 and converts it so that it's relative to coordinate space coords1
get a function that maps index-coordinates of image0-coordinate-space to the index-coordinates of image1-coordinate-space
note that if you're mapping lots of indexes using
Array.map
, it would be 40-times faster to use the lambdacalc.vectorize1 function insteadExample
Derivation
/** the equation for
mask_intervals
can be easily derived as follows:p0 = px of data
,y0 = y-coords of pixel in data
,x0 = x-coords of pixel in data
,w0 = width of data
,c0 = channels of data
p1 = px of mask
,y1 = y-coords of pixel in mask
,x1 = x-coords of pixel in mask
,w1 = width of mask
,c1 = channels of mask
y = y-coords of mask's rect
,x = x-coords of mask's rect