In image processing, why is it recommended to loop over Y first and then X second? -
i've read in few places when processing pixels of image, recommended loop on y , x pixels because more memory efficient. why so?
a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 c4 d1 d2 d3 d4
supposing that's image (and sort of coordinates it's points), stored in memory in string, like:
a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 c4 d1 d2 d3 d4.
let's simulate options:
for x , y:
a1 b1 c1 d1 a2 b2 c2 d2 a3 b3 c3 d3 a4 b4 c4 d4
now check on string, how messy access (just random reads, right?)
nor, y , x
a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 c4 d1 d2 d3 d4
see? straight forward read!
that's why.
Comments
Post a Comment