I'm trying to **convert the 3d array returned by cv2.imread to the continguous rgb byte array**, in order to display in GTK. And below is my conversion code:

```
def ndarr2rgb(img):
    r_arr = img[:, :, 0].ravel()    # read channel
    g_arr = img[:, :, 1].ravel()    # green channel
    b_arr = img[:, :, 2].ravel()    # blue channel
    numItems = img.shape[0] * img.shape[1] * img.shape[2]   # number of entries in byte array
    z = img.shape[2]                # z dimension, always equal to 3
    arr = np.zeros((numItems, 1))
    # to fill the byte array with r,g,b channel
    for i in xrange(0, numItems):
        if i % z == 0:
            arr[i] = r_arr[i/z]
        if i % z == 1:
            arr[i] = g_arr[i/z]
        if i % z == 2:
            arr[i] = b_arr[i/z]
    return arr

```

So, in my code, I first get the three dimensions separately into r\_arr, g\_arr, b\_arr, then I put the values in the order or RGB into the 'arr'. So after the iteration the array 'arr' will be like 'r0, g0, b0, r1, g1, b1, ...' 

And then I use "**GdkPixbuf.Pixbuf.new\_from\_data**" function to get the pixbuf from the arr returned by the "**ndarr2rgb**" function above. And I use "**image.set\_from\_pixbuf**" to display the image. But I got the following result:  

![enter image description here](https://i.stack.imgur.com/3to12.png)
It's like that there is some noisy area, so please help me solve my problem, thx.