Probably the best approach to the problem would be to implement an algorithm which allows to generate pixel positions in the original image along the Line without using the FrontEnd
I think ImageTransformation
doest just that. Using your definitions:
r = Min[id]/2;
dir = N@AngleVector[α];
(*modify step distance so we step at least 1 pixel in x or y \
direction*)
dir = dir/Max[Abs[dir]];
profile =
First@ImageData@
ImageTransformation[img,
center + #[[1]] dir + {1, 0} &, {Round[r], 1}, DataRange -> Full,
PlotRange -> {{0, r - 1}, {0, 1}}, Resampling -> "Nearest"];
ListLinePlot[{profile, radialProfile}, PlotRange -> All]
There still is an unwanted interpolation, try simple check when α=0 and center = Round[Mean /@ pr];: radialProfile - PixelValue[img, Table[center + i {1, 0}, {i, 1, 502}]] returns only zeros while profile - PixelValue[img, Table[center + i {1, 0}, {i, 1, 501}]] gives many zeros but also many interpolated values.
I agree this is weird. I'm guessing Resampling->"Nearest"
interpolates if a coordinate is exactly between two pixels? But I believe this is fixable by rounding coordinates and shifting them to pixel centers (Round[pt]-.5
):
profile =
First@ImageData@
ImageTransformation[img,
Round[center + #[[1]] dir] - .5 &, {Round[r], 1},
DataRange -> Full, PlotRange -> {{0, r - 1}, {0, 1}},
Resampling -> "Nearest"];
profile - PixelValue[img, Table[center + i {1, 0}, {i, 0, 500}]]