logo

请问为什么灰度图像的二值化后图像与RGB图像二值化后图像的大小不一?

2019-07-02 14:51
B
SewiChou

如图所示,当Image是灰度图的时候使用阈值二值化得到的图像只有一个图层,图像大小是正确的;但是当image为RGB的时候生成的图像就有两个图层,这导致RGB图像的二值化图像无法正常进行腐蚀和膨胀操作,求大神解答!

611de455-7270-49f6-aacf-19963f881d6f.png
bbeff11a-43a8-4173-9079-2914df220f67.png
2019-07-02 15:42
I
网红小智智 星瞳科技

如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片

I
网红小智智 星瞳科技

并且提供具体的错误信息。错误现象。

B
SewiChou

RGB图像代码:

import sensor, image, time

sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.RGB565)
sensor.skip_frames(time = 2000)
clock = time.clock()

# Use the Tools -> Machine Vision -> Threshold Edtor to pick better thresholds.
threshold_dark = (70, 100, -77, 76, 19, 74)
gray_threshold = (80, 255)


while(True):
    clock.tick()
    img = sensor.snapshot()
    img.binary([threshold_dark])
    # img.erode(100)
    # img.dilate(5)
    print(img)

灰度值图像代码

# Color Binary Filter Example
#
# This script shows off the binary image filter. You may pass binary any
# number of thresholds to segment the image by.

import sensor, image, time

sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.skip_frames(time = 2000)
sensor.set_auto_whitebal(True)  # 开启自动白平衡
clock = time.clock()

# Use the Tools -> Machine Vision -> Threshold Edtor to pick better thresholds.
threshold_dark = (70, 100, -77, 76, 19, 74)
threshold_light = (86, 100, -26, 8, -3, 45)
gray_threshold = (80, 255)


while(True):
    clock.tick()
    img = sensor.snapshot()
    img.binary([gray_threshold])
    # img.erode(100)
    # img.dilate(5)
    print(img)
2019-07-02 15:54
I
网红小智智 星瞳科技

这个问题已解决。

请更新固件到最新版本。3.4.1