随机复制一个矩形随机区域并将其粘贴到numpy中的另一个图像上

时间:2018-05-06 06:11:42

标签: python numpy

我一直在尝试复制宽度和高度为[128,1024]的矩形随机区域,但有时我会碰到

    public void MakeWidget (RaycastHit2D hit){
    if (!EventSystem.current.IsPointerOverGameObject) {
        Tower newWidget = Instantiate (widgetBtnPressed.WidgetObject);
        newWidget.transform.position = hit.transform.position;
        RegisterWidget (newWidget);
        widgetBtnPressed = null;}
    }
    public void RegisterItemSpot (Collider2D itemSpot){
    ItemList.Add(itemSpot);
    }
    public void RegisterWidget (Widget widget)
    {
    WidgetList.Add(widget);
    }

这是我的代码

---> 29 I_rcv[a:b, c:d] = dnr_patch
     30 pyplot.imshow(I_rcv)

ValueError: could not broadcast input array from shape (425,91,3) into shape (959,91,3)

编辑: 以下是变量值。图像具有随机形状,我需要选择供体图像,裁剪补丁并将其放置在接收器上。

rcv = "path/to/image/RCV.JPG"
dnr_1 = "path/to/image/DNR.JPG"

I_rcv = cv2.imread(rcv)
I_dnr = cv2.imread(dnr_1)
a = random.randint(0, min(I_dnr.shape[0] - 1024, I_rcv.shape[0] - 1024))
b = a + random.randint(1, 1024)
c = random.randint(0, min(I_dnr.shape[0] - 128, I_rcv.shape[0] - 128))
d = c + random.randint(1, 128)
dnr_patch = np.copy(I_dnr[a:b,c:d])
I_rcv[a:b, c:d] = dnr_patch

0 个答案:

没有答案