I'm writing a code that allows the user to choose some regions in an image and then I shall show the image with the regions in gray (different gray level for each different region). The user doesn't have to choose every region in the image, so if the image has 5 regions he could choose just 1 or 2,3... The exact procedure is this: The user chooses 2 pixels for every region he wants, I create a subimage with this bounding box that only includes pixels of the region. Then I calculate the first order moments (mean, variance, skewness and kurtosis) of the subimage. The only step left is to find all the pixels in the image that pertain to that region applying neighbourhood operations.
I have a value of each order moment for each region, but the range of values for these subregions I calculate to specify if a pixel pertains to the region may vary. So the problem I have is that I don't know how to create a threshold to specify if a pixel is included into a region or not.
Maybe there's some function that allows you to input a value and tells you which is the closer value from a range of values?