I've read in a few places that when processing the pixels of an image, it is recommended that you loop over Y and then X pixels because it is more likely to be memory efficient. Why is this so?
A1 A2 A3 A4
B1 B2 B3 B4
C1 C2 C3 C4
D1 D2 D3 D4
Supposing that's your image (and some sort of coordinates to it's points), it is stored in memory in a string, just like:
A1 A2 A3 A4 B1 B2 B3 B4 C1 C2 C3 C4 D1 D2 D3 D4.
Let's simulate those options:
For X and then by Y:
A1 B1 C1 D1 A2 B2 C2 D2 A3 B3 C3 D3 A4 B4 C4 D4
Now check on the string, how messy those access would be (just like random reads, right?)
Nor, For Y and then by X
A1 A2 A3 A4 B1 B2 B3 B4 C1 C2 C3 C4 D1 D2 D3 D4
See? Straight forward read!
That's why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With