Import Image component - fill irregular polygon with sampled image

Hi everyone,

Question regarding the Import Image (IMG) component. For purely aesthetic reasons, I would prefer to use this component - when the X/Y sample values are set low it looks quite interesting.

I would like to apply an image to fill one or more polygons. If I use the outlines as is, this is the result. I don’t mind that the rotation of the images vary, but it would be interesting to know how this component calculates the rotation.

I thought about finding the bounding box of each closed polyline and then applying the image to that instead, which would solve the gaps problem. But now I don’t know how to crop the image. Any ideas? I suppose I could just overlay a white coloured surface with the polygon areas cut out, but if polygons are going to be close together then you’re going to get image overlaps which I don’t want.

Lastly, ideally I would like to be able to just drop an image into an image sampler component, instead of having to manually copy and paste the file path every time, any idea how to perhaps do that? The Import Image component only wants to accept a file path input so I guess this won’t be possible. I would appreciate any help! Thanks.

query image sampling cropped.gh (13.5 MB)

I think we need the image.

Use the polygons to trim the mesh output?

You can use the file path selector to choose an image. (colored yellow below)

I used my own image, aligned with the longest edge of each polygon. Had to slightly scale up the bounding box to avoid invalid mesh output from MSplit (Mesh Split).


image sampling cropped_2024Aug17a.gh (18.0 KB)

Thanks for your response! I noticed an odd bug with this definition if the sample count value is low. If you put it down to 5, it goes a bit wonky! For aesthetic reasons I’m mostly interested in a lower sample count, any ideas as to why this is happening?

I didn’t bother to sort the output of MSplit, which is never a good idea after any split operation because fragments are not guaranteed to be in any particular sequence.

EDIT: Retrofitted better method after MSplit.


image sampling cropped_2024Aug17bb.gh (19.7 KB)

Obvious, eh?

NOTE: The image gets slightly distorted because the aspect ratio of the bounding boxes doesn’t match the original image.

1 Like

In that case, aspect ratio may not matter to you? Even so, I added the gray group to match the aspect ratio of the image (3:2 for the image I used). Better without distortion, I think.

EDIT: Retrofitted better method after MSplit.


image sampling cropped_2024Aug17cc.gh (23.0 KB)

I started to demonstrate a simple change that skips aligning the image (bounding box) with the longest edge of each polygon… Then discovered that sorting by area didn’t work :exclamation: :roll_eyes: Less of the image fits when not aligned, so more is lost outside the polygons.

So implemented a different method using Pull Point that should be retrofitted to earlier code.


image sampling cropped_2024Aug17d.gh (23.4 KB)

Mine still bugs out on some polygons where it fails to crop correctly, but a bit underwhelmed with the results anyway so not that pressing to resolve.

Don’t mind the image getting a bit squeezed or stretched, but thank you for clarifying how one would go about keeping the aspect ratio constant.

The code is not difficult to understand, especially the part that decides which fragment to keep after MSplit, but it sounds like you don’t care. Oh well. :man_shrugging: