简体   繁体   English

使用我自己的最小最大值和 python 进行图像阈值处理

[英]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.例如,最小值为 300,最大值为 500,如果我的像素值介于两者之间,则为 255,否则为 0。感谢您的帮助。

Assuming you're using opencv, there's the cv2.inRange(img, min, max) function that does exactly that.假设您使用的是 opencv,那么 cv2.inRange(img, min, max) function 正是这样做的。 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.如果您想要一个与库无关的解决方案,那么您可以遍历您的图像并通过检查每个单独的像素值与您的界限来自己构建遮罩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM