stippled line variable point spacing from raster
 1-16  17-36  37-56  57-60

Previous
Next
 From:  pressure (PEER)
10809.17 In reply to 10809.2 
Michael,

Thanks for the node links and Grasshopper recommendation. Brian and Ed have gotten me to the point of understanding that mapping between MoI 3D world units and pixels will be a problem. I could probably do it manually by putting some fiducial marks on the raster in photoshop and then manually place point objects on the fiducials as they appear in the 3D scene. I'm wondering if there's a better way.

I went through http://web.archive.org/web/20180705035034/http:/moi.maxsm.net/api and found these methods and properties related to background images:

fileName
hidden
remove
backgroundImageDrawOrder
backgroundImageShowIn
backgroundImageTransparency
getBackgroundImages
alignbackgroundimage
backgroundimage

In the GUI I can see View > Image > Properties Width and Height. Can I retrieve Width and Height in a script?

Are there any methods or properties that would allow me to find coordinates of 3 corners of a background image?

Can I find a mapping between the corners of the displayed background image and the corners of the bitmap file from which it was generated? In other words, map the corners even if the displayed background image is rotated, mirrored, or scaled.

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.18 In reply to 10809.15 
Link to ImageToRect.js
https://moi3d.com/forum/index.php?webtag=MOI&msg=10730.7

Placed the image in a rectangle.

- Brian

function AddImage() in commands\Image.js: Link:
https://moi3d.com/forum/index.php?webtag=MOI&msg=8571.7

EDITED: 11 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10809.19 In reply to 10809.14 
Hi Brian,

re:
> Search for +imagetorect.zip does not have any results.
> I downloaded imagetorect.zip on 6/24/2022.
>
> Where are the forum posts about this new script?

It's here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=10730.7

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10809.20 In reply to 10809.17 
Hi Peer,

re:
> In the GUI I can see View > Image > Properties Width and Height. Can I retrieve Width and Height in a script?

Yes, they are available in script as .width and .height properties on a background image.

> Are there any methods or properties that would allow me to find coordinates of 3 corners of a background image?

Yes, the .frame property on a background image object gives a MoiCoordinateFrame object which is made up of an origin point and x/y/z axis directions forming a coordinate system. The bottom left corner of the image is located at the origin point of that frame and extends by width amount along the x axis direction and by height amount along the y axis direction.

The points can be obtained like this (warning untested code):

var lower_left = img.frame.origin;
var lower_right = img.frame.evaluate( img.width, 0 );
var upper_right = img.frame.evaluate( img.width, img.height );
var upper_left = img.frame.evaluate( 0, img.height );

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
10809.21 In reply to 10809.20 
Thanks Michael!

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.22 In reply to 10809.19 
Thank you Michael.

Is there any way to get the RGB value of a point in the image file? Or some connection between image pixels and MoI screen point coordinates?
Does it have anything to do with "texture" (texels?)
Is the image file somewhere in the geometry database.
Please excuse my dumb questions.

- Brian


I do not know anything about "texture"
Found a link with a kitten:
https://www.cs.uregina.ca/Links/class-info/315/WWW/Lab5/

"Textures--rectangular arrays of data. The data can be color data, luminance data, or color and alpha data"
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10809.23 In reply to 10809.22 
Hi Brian,

re:
> Is there any way to get the RGB value of a point in the image file? Or some connection between
> image pixels and MoI screen point coordinates?

There isn't anything for that in MoI's own script interface but you can use one of the HTML documents that are used for MoI's UI to access image pixel data in a script.

Like Ed writes above, check out Max's heightmap command for an example. I've attached it.

- Michael

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.24 In reply to 10809.23 
Thank you Michael.

I now think that there is enough information to map a MoI point over an image, into the original "canvas" image pixel array.
For one canvas image pixel, there are 4 entries in the array, R value, G value, B value, and Alpha value.

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.25 In reply to 10809.23 
Michael, Thank you for the most recent version of Heightmap.
It works in MoI5beta as well.
(The pixel width count of the two images that I tried were cut in half.)
Heightmap has a lot of the required code.


Raster gradients can be produced in imagemagick, a free program.
https://imagemagick.org/script/gradient.php
There are numerous versions, including 6 Windows versions and 1 Mac OS version.
De to lack of experience, I am not expressing any opinion expressed about the worth of this program.

- Brian

Does MoI Image command work with image files with 8 or 16 bits-per-pixel,
Static, or dynamic, (Whatever those mean), or HDRI (high dynamic-range imaging)?

EDITED: 11 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10809.26 In reply to 10809.25 
Hi Brian,

re:
> Does MoI Image command work with image files with 8 or 16 bits-per-pixel,
> Static, or dynamic, (Whatever those mean), or HDRI (high dynamic-range imaging)?

It only works with images in PNG, TIF, JPEG, GIF, and BMP formats and I don't think that any of those can contain HDRI image data.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.27 
This link has some generic code for "transforming the coordinates from the specified coordinate system into pixel coordinates."
(2.1.2 Real-number Coordinate Systems)

https://math.hws.edu/graphicsbook/c2/s1.html#:~:text=In%20terms%20of%20coordinates%2C%20a,to%20right%2C%20starting%20with%20zero.

One step is to set up the various image rectangles. These are world, local, canvas, and primary.
MoI World coordinates come from MoI Local (cplane) coordinates using .evaluate. (See Michaels code.)

The primary image is the source PNG, TIF, JPEG, GIF, or BMP.
A primary image ( width, height ) ( 1920, 1080 ), has 1920 pixel columns, and 1080 pixel rows.
A test primary image will be ( 6, 5 ). (or maybe ( 12, 8 ).

The address for a pixel is ( rowNum, colNum )
the pixel columns and rows are zero indexed, with upper left corner ( 0, 0, 0 ).

The canvas image is similar to the primary image. (?) (Heightmap divides x by 2)
Reversing row number from bottom to top to top to bottom: ( oldrowNumber - numRows ) ?

- Brian

I am going to assume that a screen point that falls on a pixel boundary is in the pixel to the left, or above. (???)
Except uppermost edge and leftmost edge?

EDITED: 12 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.28 
Based upon Peer's initial description:

I am thinking that the "intensity-to-points-array" should be done from a 2d CPlane.
Convert CPlane local coordinates over the image, into pixel (row,column) address of the canvas image.
World coordinates just complicate the script.
At the end of the script, the CPlane can be reset.

The reason for this is that the 2d image can be in any view, for example Top, Front, Right, etc.
Or even at some other angle. The ( X, Y ) coordinate of a local point is to be converted to a pixel address.
World coordinates could introduce z into the (x,y) mix, and mess up the conversion to pixel address.
For example, Front view is 2d world ( x, z ), but local ( X, Y ), with Z = 0, or Z = constant.
Right view is 2d world ( y, z ), but local ( X, Y ), with Z = 0, or Z = constant.

?

- Brian

I'll make the assumption that the canvas image is the same "resolution" as the primary (e.g. PNG) image.
I guess that the canvas image is somewhere in memory, not a MoI geometry object. (?)

The method to ghet the 2d CPlane of an image was given by Michael, I think.

So divide the local image by columnNum zones, along X,
and divide the local image by rowNum zones, along Y.
(Convert real number X, Y coordinates into integers for each zone...)
Reverse Y coordinates for rowNum to be zero at upper left corner.

EDITED: 12 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.29 In reply to 10809.5 
Hi PEER,

>>>But maybe before going into details, can you think of another way of spacing out points along a curve so the the distance between each pair of points is roughly proportional to the local luminance of an underlying image? Maybe there's a straighter path that I'm not thinking of.

If you have a mathematical formula for the "raster gradient" of the luminance, that could perhaps be used to array the points along the curve.

The programs that create the raster gradients use some mathematical method. See their source code, or do internet search?

https://gis.stackexchange.com/questions/311688/how-to-make-a-raster-gradient-in-any-direction-in-r

https://www.i-programmer.info/programming/javascript/14966-javascript-canvas-gradient-a-pattern-fills.html

https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/

https://www.youtube.com/watch?v=nMUMZ5YRxHI

- Brian

EDITED: 12 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
10809.30 In reply to 10809.29 
Brian,

I got pretty close to what I want working in another program. For now I'm going to use that.

Have a good weekend!

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.31 
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

EDITED: 13 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.32 
I guess the code broke the Edit feature.

To add:
P′raster.x and P′raster.y are the coordinates of the primary image (PDF, JPEG, TIF, BMP, etc) pixel associated with Pprime.

The second and third "pseudo" code blocks above, are quotes from the link.

Elsewhere, I found more definitions of "luminance" calculation using RRBGGG / 6, etc.

- Brian

The (line) curve, and its angle theta, can be used to calculate the distance along the line for the next pPrime point.
Calculate the width and height of a rectangle by dividing 2d screen image dimensions by number of primary row and column pixels.
The distance is a hypotenuse. Use trigonometry or pythagorean formula.
Or just add dx and dy to old (pPrime point.)

It is nice to find some (relatively easy) code and explanations.

EDITED: 13 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.33 
Given a (continuous) curve in an ( x, y ) plane, which goes from xMin to xMax, and which for every x, has a single y value.
(Like for a single valued function.)
A circle and ellipse do not qualify. The bottom half of a circle would qualify.


How to Array the start point along the curve, with constant x intervals.
I do not think that there is a script for doing this?
ArrayCurve of startpoint of the curve usually is spaced differently.

This can be done by placing a horizontal line below the curve, and using ArrayCurve to array the startpoint of the line along the line, and then projecting the points to the "single valued curve".

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10809.34 In reply to 10809.33 
Hi Brian,

re:
> How to Array the start point along the curve, with constant x intervals.

Probably you'd need to create a vertical line at every x position and then use the 'intersect' factory (see Intersect.js) to intersect the line with your function curve, that should generate a point object.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10809.35 In reply to 10809.34 
Hi Michael,

Intersections is a good idea.

Create guide line above curve, and guide line below curve.
Run LineWeb to get uniform deltaX lines between the two guide lines.
Intersect lines with curve to create points on the curve.
Investigate the order of the points.

Look for algorithm to scan the points on a curve, from curve start to curve end, and place the points in ordered array.
This could then apply to curves which loop back .
(Unless MoI already orders the points along a curve?)

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10809.36 In reply to 10809.35 
Hi Brian,

re:
> Look for algorithm to scan the points on a curve, from curve start to curve end, and
> place the points in ordered array.
> This could then apply to curves which loop back .
> (Unless MoI already orders the points along a curve?)

In your script you can call intersect separately for each vertical line with the function curve
and since you are making those vertical lines you should generate them in increasing order
so that your intersections will be ordered also.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
Show messages:  1-16  17-36  37-56  57-60