thresh_im = (gray_im > 230) + (gray_im < 20);
时间: 2024-05-26 09:19:06 浏览: 6
这段代码的作用是将灰度图像中灰度值大于230或小于20的像素点的值设为1,其余像素点的值设为0,生成一个二值图像。
具体来说,`(gray_im > 230)` 会生成一个与灰度图像 `gray_im` 同样大小的矩阵,其中元素值为True的位置对应灰度图像中灰度值大于230的像素点,其余位置为False。同理,`(gray_im < 20)` 会生成一个矩阵,其中元素值为True的位置对应灰度图像中灰度值小于20的像素点,其余位置为False。
接着,这两个矩阵进行逻辑或运算,即将两个矩阵对应位置的元素进行或运算,得到一个新的矩阵,其中元素值为True的位置对应灰度图像中灰度值大于230或小于20的像素点,其余位置为False。最后将这个矩阵中的True值强制转换为1,False值强制转换为0,即得到了二值图像。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)