# Converting a PyCall numpy ×3 Array{UInt8, 3} to RGB

**URL:** https://discourse.julialang.org/t/converting-a-pycall-numpy-x3-array-uint8-3-to-rgb/70537
**Category:** Visualization
**Tags:** images, pycall
**Created:** [October 28, 2021, 7:58am UTC](https://discourse.julialang.org/t/converting-a-pycall-numpy-x3-array-uint8-3-to-rgb/70537 "2021-10-28T07:58:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Pytrator](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@Pytrator](https://discourse.julialang.org/u/Pytrator)
#### Post date: [October 28, 2021, 7:58am UTC](https://discourse.julialang.org/t/converting-a-pycall-numpy-x3-array-uint8-3-to-rgb/70537/1 "2021-10-28T07:58:28Z")

</div>

Hey guys, I use the NumPy per PyCall to get screenshots of my desktop.

I get these images back as 1440×3440×3 Array{UInt8, 3}

Discord user borodi#9175 already shared a function of him that converts this array to a BGR.

```julia
opencvtojulia(abc) = BGR.(reinterpret.(N0f8,abc[:,:,3]),reinterpret.(N0f8,abc[:,:,2]),reinterpret.(N0f8,abc[:,:,1]))

```

Because it changes a lot of colors to the wrong ones i have to fix something in it.

Has somebody an idea how to get RGB images from this function or what else can get me RGB?

Thanks for your help!

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [October 28, 2021, 9:03am UTC](https://discourse.julialang.org/t/converting-a-pycall-numpy-x3-array-uint8-3-to-rgb/70537/2 "2021-10-28T09:03:10Z")

</div>

The precise steps may depend on your data (e.g., `RGB` vs `BGR`; Julia supports both), but this demo may get you started:

```julia
julia> using PyCall, ImageCore, ImageView

julia> si = pyimport("skimage.data")
PyObject <module 'skimage.data' from '/usr/lib/python3/dist-packages/skimage/data/ __init__.py'>

julia> dat = pycall(si.rocket, PyArray);

julia> img = reinterpretc(RGB{N0f8}, PermutedDimsArray(dat, (3, 1, 2)));

julia> imshow(img)

```

ImageCore has an extensive set of composable no-copy operations for reinterpreting the meaning of raw data; with them, you should be able to do anything you want. Please see the docs at [ImageCore.jl · ImageCore](https://juliaimages.org/ImageCore.jl/stable/)

---

<div class="post-metadata">

### Author: ![Pytrator](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@Pytrator](https://discourse.julialang.org/u/Pytrator)
#### Post date: [October 28, 2021, 9:20am UTC](https://discourse.julialang.org/t/converting-a-pycall-numpy-x3-array-uint8-3-to-rgb/70537/3 "2021-10-28T09:20:52Z")

</div>

Wow! Thanks what a great solution!

reinterpretc(RGB{N0f8}, PermutedDimsArray(dat, (3, 1, 2))); solves it alone!

Many thanks!

---

<div class="post-metadata">

### Author: ![Alon\_Ben-Arieh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alon_ben-arieh/32/38256_2.png) [@Alon\_Ben-Arieh](https://discourse.julialang.org/u/Alon_Ben-Arieh)
#### Post date: [July 25, 2022, 5:26pm UTC](https://discourse.julialang.org/t/converting-a-pycall-numpy-x3-array-uint8-3-to-rgb/70537/4 "2022-07-25T17:26:01Z")

</div>

Thank you so much!
