【问题标题】:filling desired color while rotating the image in scipy在 scipy 中旋转图像时填充所需的颜色
【发布时间】:2013-04-02 17:44:31
【问题描述】:

我正在使用 scipy 旋转图像,如下所示

    scipy.misc.imrotate(im,60)

旋转后的图像填充了黑色值,我想要白色。

有什么建议吗?

谢谢

【问题讨论】:

    标签: python image rotation scipy


    【解决方案1】:

    scipy.misc.imrotate 只是在幕后使用 PIL。您可以简单地使用 PIL 来完成,但它非常笨重。

    最好只使用scipy.ndimage.rotate。 (scipy.misc 中的函数有些晦涩,很少使用。)

    cval kwarg 控制“背景”值。

    在你的情况下:

    import numpy as np
    import scipy.ndimage
    
    data = 256 * np.random.random((10,10))
    data = data.astype(np.uint8)
    
    rotated = scipy.ndimage.rotate(data, 60, cval=255)
    print rotated
    

    产量:

    [[255 255 255 255 255 255 255 255 255 255 255 255 255 255]
     [255 255 255 255 255 150 255 255 255 255 255 255 255 255]
     [255 255 255 255 160 234 179 152 255 255 255 255 255 255]
     [255 255 255 255 120 206 114  19 173 188 255 255 255 255]
     [255 255 255 172 113 144 159 162 175  89  43  62 255 255]
     [255 255 255  81 170 194 205 137 158 190 196 123 186 255]
     [255 255 115  67 118 101  53  33 108  34 125  61 255 255]
     [255 255 176 126 113 189 170 120 118  10 182 165 255 255]
     [255 150 209 101   9 146 213  99 134 162 133 255 255 255]
     [255 255 190 126 194 159 119  67 171 240 143 255 255 255]
     [255 255 255 255 174 184 211  99 103 139 255 255 255 255]
     [255 255 255 255 255 255 167 232  70 247 255 255 255 255]
     [255 255 255 255 255 255 255 255 102 255 255 255 255 255]
     [255 255 255 255 255 255 255 255 255 255 255 255 255 255]]
    

    【讨论】:

      猜你喜欢
      • 2023-02-20
      • 2015-03-24
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 2016-09-01
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      相关资源
      最近更新 更多