Search code examples
pythonimage-processingbinaryminmaximage-thresholding

Image thresholding with my own min-max value with python


I have an image to threshold. But I dont want to classical methods. I have my own min and max threshold value. How can i apply this threshold values to my image and get a binary mask. For example min is 300 and max is 500 if my pixel value is between these I get 255 if not I get 0. Thanks for helping.


Solution

  • Assuming you're using opencv, there's the cv2.inRange(img, min, max) function that does exactly that. If you want a library agnostic solution then you could iterate through your image and build the mask yourself by checking each individual pixel value against your bounds.