opencv如何填充阈值图像(一些白色部分)?
我创建了一个脚本来阈值微观图像,我想知道如何填充图像的某些白色空间。如您在图片中所见,我的目的是制作一个过滤器,以仅分开蓝色区域。应将所有其他白色区域(红色箭头)擦除或转换为黑色。
这是我的代码:
original = cv2.imread(inputfile + ".jpg")
#cv2.imread(inputfile + ".jpg")
original = cv2.resize(original, (1280, 960)) #resize of original image
img = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
median = cv2.medianBlur(img, 3)
ret, th = cv2.threshold(median, 160, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
kernel = np.ones((1,1), np.uint8)
opening = cv2.morphologyEx(th, cv2.MORPH_OPEN, kernel)
edge_touching_removed = clear_border(opening)
contours, hierarchy = cv2.findContours(edge_touching_removed, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
事实是...应用此阈值后,我将在蓝色区域应用轮廓以使区域陷入困境。没关系...但是我不知道如何擦除其他区域。
我应该导出该阈值图像,然后手动绘画?我不想这样做...我在想也许有手动填写代码。我使用了CV2形态,但我不知道我是否需要为此进行另一个过滤器。
谢谢
I<ve created a script to threshold a microscopic image and I would like to know how to fill some white spaces of the image. As you see in the picture my aim is to make a filter to separate only the blue zones. All other white zones (red arrow) should be erased or converted (filled out) to black.
Here is my code:
original = cv2.imread(inputfile + ".jpg")
#cv2.imread(inputfile + ".jpg")
original = cv2.resize(original, (1280, 960)) #resize of original image
img = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
median = cv2.medianBlur(img, 3)
ret, th = cv2.threshold(median, 160, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
kernel = np.ones((1,1), np.uint8)
opening = cv2.morphologyEx(th, cv2.MORPH_OPEN, kernel)
edge_touching_removed = clear_border(opening)
contours, hierarchy = cv2.findContours(edge_touching_removed, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
The thing is ... after apply this threshold I will apply contours to the blue zone to caculate area. That is ok... but the thing is I don<t know how to erase the others zones.
Should I export that threshold image and I painted manually? I dont wanna do that... I was thinking that maybe there is a manual fill out code. I used the cv2 morphology but I dont know if I need to do another filter for that.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论