(Since there is already more than one hint, I am moving the comments to an answer):
I think this is too specific for a plugin - and has a major problem in that in a "real world" image, like a photo, color differences perceived to the eye are not so sharp as to be automatically distinguished.
Since you have GIMP in your stack, my suggestion is for you to use GIMP's measure tool manually - and if you really have a use case to automate that, to use a stack like Python + OpenCV. https://docs.gimp.org/2.10/en/gimp-tool-measure.html
you mean develop a gimp plugin? or just python with opencv. what could
be more easy considering I want to manually draw the line?
If you want to manually draw the line, then a GIMP plugin would be easier. But in that case, that is an extra argument of manually taking note of the distances with the measure tool.
If you opt to try the plug-in anyway, I'd suggest abusing the "path tool" for drawing the line (a straight, degnerate case of a bezier curve, created with two simple clcks with the path tool), before calling your plugin code - that way the line coordinates are a given for the plugin, using the path API.
I have a nice script I made more than a couple years back that uses the Path Tool in this way to capture 3 points and draw a circle through them - this might be a starting point for you: