Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to get the position of first pixel from a given cardinal direction using Value Processor?

Participant ,
Sep 17, 2025 Sep 17, 2025

I've spent more time than I anticipated.. After creating my LED board generator (which is much more complex than this simple problem) I though this would be a piece of cake... but alas..

 

In the end I want the bounding box of an arbitrary shape (whole shape, if the image got two disjoint shapes, then the total bounding box)

So naturally the easiest (not the most efficeint I presume) way I could think was, Scan the input from all four sides and stop at the first pixel encounter..

 

But I just couldn't.. from any one side. Attaching my failed attempts along with an SS for better explanation.

TOPICS
How to , Substance Graph
89
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 17, 2025 Sep 17, 2025

Hello Ayush,

your approach is going in the right direction, but is as you mentioned not very optimized, in the value processor alone you won't have another chance but if you are using a Pixelprocessor instead, it gets actually very easy and optimized, because the Pixelprocessor calculates every pixel in parallel and you can exploit this, in order to get the total bounding box of an input very fast.

 

Here is an overview over the compete graph, ignore the first section, it's just an input, you wo

...
Translate
Community Expert ,
Sep 17, 2025 Sep 17, 2025

Hello Ayush,

your approach is going in the right direction, but is as you mentioned not very optimized, in the value processor alone you won't have another chance but if you are using a Pixelprocessor instead, it gets actually very easy and optimized, because the Pixelprocessor calculates every pixel in parallel and you can exploit this, in order to get the total bounding box of an input very fast.

 

Here is an overview over the compete graph, ignore the first section, it's just an input, you would probably use an input Node for it and do this in a subgraph, in order to reuse it, whenever you need it.

full_graph.png

 

The Algorithm:

  • Prepare your Data, for every Pixel greater 0 (a valid pixel) you set the current Position in the grid as Output, for every invalid pixel you set the output to 2 in the red and green channels and to -1 in the blue and alpha channels. This generates a mask, of -1 and 2 for the min and max values of x and y.function_graph_data_prepare.png

 

  • Next Step is the core idea behind the whole thing, you downsample the image step by step until it's a 1x1 texture, in every downsample step you check the 4 neighbours of every pixel if they are valid and if so, output the minimum and maximum values of x and y of all 4 neighbours. You basically calculate the bounding box of a 2x2 pixel area, in the next step you repeat this step and merge the 4 neigbouring bounding boxes into a new bounding box.subgraph_downsample_loop.pngfunction_graph_downsample_loop.png

 

  • In the last Downsample Step you have only a 1x1 Texture, with all the "mini" - Bounding Boxes merged into one Bounding Box, which lets you extract the min and max values from the Bounding Box in the following order:
    • red: bbox min x
    • green: bbox min y
    • blue: bbox max x
    • alpha: bbox max y

 

Stay healthy and creative Marco

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 18, 2025 Sep 18, 2025
LATEST

Thank you Marco for the in-depth solution. I'll try this and some other algorithms too.

I believe thinking like this would be easier if I learn intermediate level of graphics programming and building shaders... Also a ton of maths. Gotta refresh many things I learned and forgot after high school.

Cheers :clinking_glasses: 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines