I would start with imrect . It is draggable and you can add callbacks to it.
(Taken directly from MATLAB help)
figure, imshow('cameraman.tif'); h = imrect(gca, [10 10 100 100]); addNewPositionCallback(h, @(p) title(mat2str(p, 3))); fcn = makeConstrainToRectFcn('imrect', get(gca,'XLim'), get(gca, 'YLim')); setPositionConstraintFcn(h, fcn);
Change addNewPositionCallback to suit your needs. In particular, get the right pixels from the image (using the position) and calculate everything you like.
Andrey Rubshtein
source share