Congratulations PEER.
I might do a little more work on a version of "array by luminance".
This morning I found some "simple" code to convert from a 2D ScreenCanvas to pRaster coordinates (pixel).
https://www.scratchapixel.com/lessons/3d-basic-rendering/computing-pixel-coordinates-of-3d-point/mathematics-computing-2d-coordinates-of-3d-points.
Note that the link is doing something slightly different than the "array by luminance", but the code can be (easily I think) altered to apply.
Definitions:
The 2D ScreenCanvas is the 2D image on the MoI screen.
The cPlane coordinate system has its origin at the center of the 2D ScreenCanvas.
code:
(Note, the user picks the lower left corner of the MoI Image with pointpicker, and cPlaneInitial is created.
the cPlane Frame is created from cPlaneInitial, as in the recent Elastica script.)
Point Pprime is a MoI point on (or on top of) the 2D ScreenCanvas.
code:
(Note that ScreenCanvas is different from the Canvas of Heightmap.)
"Since P' is a 2D point, it is defined with respect to a 2D coordinate system which in CG we call the image or screen coordinate system. This coordinate system marks the centre of the (screen)canvas;"
code:
"The first thing we are going to do is to remap P' coordinates in the range [0,1]. This is mathematically easy. Since we know the dimension of the (screen) canvas, all we need to do is apply the following formulas:
P′normalized.x=P′.x+width/2width
P′normalised.y=P′.y+height/2height
Because the coordinates of the projected point P' are now in the range [0,1], we say that the coordinates are normalized. For this reason, we also call the coordinate system in which the points are defined after normalization, the NDC coordinate system or NDC space. NDC stands for Normalized Device Coordinate. The NDC coordinate system's origin is situated in the lower-left corner of the canvas. Note that at this point, the coordinates are still real numbers, only they are now in the range [0,1].
The last step is simple. All we need to do is now multiply the projected point x- and y-coordinates in NDC space, by the actual image pixel width and pixel height respectively. This is a simple remapping of the range [0,1] to the range [0,Pixel Width] for the x-coordinate, and [0,Pixel Height] for the y-coordinate respectively. Now though that pixel coordinates are integers, thus rounding off the resulting numbers to the smallest following integer value is necessary (to do that, we will use the mathematical floor function; it rounds off a real number to its smallest following integer). After this final step, P' coordinates are defined in raster space:
P′raster.x=⌊P′normalized.x∗ Pixel Width⌋
P′raster.y=⌊P′normalized.y∗Pixel Height⌋
In mathematics, ⌊a⌋, denotes the floor function.
There is a small detail though we need to take care of. The y-axis in the NDC coordinate system points up while in the raster coordinate system points down. Thus, to go from one coordinate system to the other, P' y-coordinate also needs to be inverted. We can easily account for this by doing a small modification to the above equations:
P′raster.x=⌊P′normalized.x∗ Pixel Width⌋
P′raster.y=⌊(1−P′normalized.y)∗Pixel Height⌋"
P′raster.x and P′raster.y will then be used in Heightmap modified code, with the Heightmap canvas, to get the RGB or RGBA
data.
One of the several Luminance formulas will give the luminance value of the pixel.
Repeat for remaining points on the (Line) curve overlying the MoI image.
Node that the (Line) curve can be at an angle theta...
- Brian