[Python] Getting ROI as 2d numpy array using pyqtgraph.ROI.getArrayRegion

Discussão em 'Python' iniciado por Stack, Setembro 9, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to do image processing using pyqtgraph.ROI. I am able to draw multiple ROI on the image and manipulate them but I am unable to merge the ROIs and extract the information as an numpy array. It seems like I am missing some basic things but I couldn´t find a solution addressing the issue. (I am a new user and sorry if it is a silly question. Thanks in advance!)

    My code:

    ## Define ROIs
    plt2 = pg.image(image)

    roi_circle1 = pg.CircleROI([pos_x, pos_y], [2*radius_of_circle, 2*radius_of_circle], pen=pg.mkPen('r',width=2))

    plt2.addItem(roi_circle1)

    roi0 = pg.MultiRectROI([[pos_x+radius_of_circle, 0], [pos_x+radius_of_circle, pos_y]], width=5, pen=(2,9)

    plt2.addItem(roi0)

    plt2.setFixedSize(1000, 1000)
    plt2.show()

    ## Now I am trying to use one of the ROI object to crop the area as an numpy output:
    testmat=np.random.random((np.shape(image)))
    test_roi_image=pg.ROI.getArrayRegion(testmat,roi0,axes=(0, 1), returnMappedCoords=False)

    ## I am getting an error:
    test_roi_image=pg.ROI.getArrayRegion(testmat,roi0,axes=(0, 1),returnMappedCoords=False)


    TypeError: getArrayRegion() missing 1 required positional argument: 'img'

    Continue reading...

Compartilhe esta Página