hmmm, assigning to I[x*w   + ch*w] -> segfault. but, assigning to I[x   + ch*w] -> no segfault
indexing I[] -- got segfaults worked out there. But, img_data[y*w*d + ch] gives a segfault.
hmph, why does img_data[y*w*d] segfault?
loop reordering (will matter for efficiency at some point). Still same problem with img_data[y*w*d] segfaulting
img_data[y*w*d] = (uchar)0; also crashes (bus error, but same idea. and gdb confirms that it crashes on this line.)
aha! I somehow did img_data = &img_data[0]; instead of img_data = &img.data[0];. Not sure why this would even compile. Segfault is gone now.
segfault in gradMag() is back.