I am given a matrix of integers with width w_g
and height h_g
filled with values 0
to w_g x h_g - 1
and a local matrix filter with width w_l
and height h_l
. I want to map each value in the matrix to a corresponding index in the smaller matrix.
For w_g = 9
, h_g = 8
, w_l = 3
and h_l = 2
the matrix values
would get mapped to the following indices:
I got this working with the following formula:
newValue = value % w_l + ((value / w_g) % h_l) * w_l
I’m currently searching for an adaption to this formula (or a new one) since this one fails when either w_g
or h_g
aren’t multiples of w_l
corresponding h_l
. The solution shouln’t consist of if-conditions etc. I am looking for a closed formula.
Thanks in advance.
2