Image J shrinkage calculation


We want to calculate shrinkage of a ceramic material with image j programme, we will try this with drawing lines to the sample surface and determine the line length, however we have 660 photos. I know how to record macro and automate the steps for all photos.

However, what i want to know is, how can i introduce the surface of the sample to the image j and make the line stop when sample surface appears automatically. It is OK if the line stops when meets with the black background. I will add a photo to the attachments to explain the situation.

Thank you.