基于多阈值的图像二值化处理浏览.io's imread()

2024-09-30 08:20:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在想办法把一个RGB.png格式在直方图强度上归档。你知道吗

Example: smoothed RGB intensities with estimated thresholds for R,G,B

到目前为止,我可以使用<;和>;操作符使用以下代码为一个强度范围应用阈值:(如果我想知道为什么它不是第1阶段的img<;thres1。)

from skimage.io import imread
img=imread('example.png')
#intensitys
thres1 = 30
thres2 = 80
#calculate
phase1 = img > thres1
phase3 = img < thres2

现在我试着用几种方法来获得强度thres1thres2之间的像素,例如:

phase2 = thres1 < img < thres2
#also
phase2 = thres1<img & img < thres2
#and
phase2 = thres1<img
phase2 = thres2>phase2

在执行此操作时,它会显示以下值错误: 包含多个元素的数组的真值不明确。使用a.any()或a.all() 我还尝试用a.any()和a.all()处理这个案例,没有得到任何有用的结果。你知道吗

使用phase2 = np.logical_and(thres1 < img,img < thres2)错误地将第3阶段包含到第2阶段中

phase2 = np.logical_and(thres1 < img,img > thres2)错误地将第1阶段包含到第2阶段。你知道吗

Example: plot of generated image arrays for phase2 = np.logical_and(thres1 < img,img > thres2)

是否有可能通过在两个强度值之间绘制所有像素来创建包含多个阈值参数的图片?你知道吗


Tags: andltimgforpngexample错误np
1条回答
网友
1楼 · 发布于 2024-09-30 08:20:44

在尝试了很多东西之后,逆运算符为我得到了它。 看起来这就像

“给我所有像素,不包括在phase1,phase3中”

phase2 = ~(np.logical_and(phase1,phase3))

需要超过3个阶段,我仍然不知道如何处理这个。。你知道吗

相关问题 更多 >

    热门问题