1 | initial version |
Ati, I'm writing the solution as an answer so you can accept it for other users to see it.
You have to add the origin of the ROI as an offset:
row = (j/Dist.rows) + (j%Dist.rows) + roiOrigin.y;
col = j%Dist.cols + roiOrigin.x;