MATLAB: HOW TO GET CENTRAL PIXEL

image processing

hI
how to get the central non-zero valued pixel in a row of an image. My aim is to get the principal axis of an image. I already operate different morphologocal operation to get this. I got the thin axis with single non-zero vale in some row BUT not all row. In some row there are multiple number of non-zer valed pixel.
so i want to extract the central pixel (non-zero valued) in each row.
HELP ME.

Best Answer

[~, central_pixel_idx] = min( abs( bsxfun(@times, logical(YourGrayImage), 1:size(YourGrayImage,2)) - size(YourGrayImage,2)/2)) );