Link to home
Start Free TrialLog in
Avatar of hbiz
hbiz

asked on

Non uniform 2d grid subdivision based on gradient map

Given a black and white gradient map where pure black is 0.0 and pure white is 1.0. I'd like to generate coordinates for a 2d grid that has squares of varying sizes such that areas on the map that are whiter generate smaller squares and areas that are blacker generate squares of larger size. These squares will vary between min_size and max_size depending on the color of the map.

Perhaps this diagram could help explain what I'm trying to achieve:

 nonuniform-subdivision.jpg
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

Instead of a max_size and a min_size, use a max_size and a num_sizes. This will avoid potential pitfalls if max_size is not min_size times a power of 2. Each successive size will be exactly half the previous one. (So max_size should still be a power of two)

Draw a grid of max_size over the whole image. Then iterate through each grid square. Take the average (or max, your choice) color of the square. If it is above the threshold (current_size_index/num_sizes) then draw the horizontal and vertical lines through the middle, then recursively do the same process on each subsquare (incrementing the current_size_index).
The whole thing will just be one simple recursive function.
ASKER CERTIFIED SOLUTION
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hbiz
hbiz

ASKER

Thanks! this is brilliant!