【问题标题】:How can I convert this image to grayscale in Python 3.6?如何在 Python 3.6 中将此图像转换为灰度?
【发布时间】:2017-10-31 15:49:31
【问题描述】:

我有这个代码:

    bPlane = myImage[:,:,0] - 0.5*(myImage[:,:,2]) - 0.5*(myImage[:,:,1]);
    purple = bPlane > 20
    purple2 = morphology.remove_small_objects(BW_2, 400);

其中 myImage 是 BGR。

如何在 Python 3.6 中将“purple2”转换为灰度图像?

【问题讨论】:

    标签: image python-3.x grayscale bgr


    【解决方案1】:

    如果您的图像一开始是一个数组 (arr),一个可能的解决方案是:

    import numpy as np
    from PIL import Image
    
    arr = np.random.rand(100,100)
    
    im = Image.fromarray(arr)
    
    gray = im.convert('L') # Converting to grayscale
    

    【讨论】:

      猜你喜欢
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-18
      • 1970-01-01
      • 2021-06-06
      相关资源
      最近更新 更多