# Converting from 24-bit image as byte array to RGB

**URL:** https://discourse.julialang.org/t/converting-from-24-bit-image-as-byte-array-to-rgb/49806
**Category:** Visualization
**Tags:** question
**Created:** [November 8, 2020, 10:28pm UTC](https://discourse.julialang.org/t/converting-from-24-bit-image-as-byte-array-to-rgb/49806 "2020-11-08T22:28:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)
#### Post date: [November 8, 2020, 10:28pm UTC](https://discourse.julialang.org/t/converting-from-24-bit-image-as-byte-array-to-rgb/49806/1 "2020-11-08T22:28:30Z")

</div>

I am working on [Data-exchange Julia-LabView - #13 by Eben60](https://discourse.julialang.org/t/data-exchange-julia-labview/46315/13) . Now I’m trying to send image data to Julia. I get image now as 3xMxN array of UInt8. How to convert it to RGB? The following works, but it must be possible to avoid convesion to floats.

```julia
# r is a 3xMxN array of UInt8
rc = r/255.0 
im2 = colorview(RGB, rc)

```

---

<div class="post-metadata">

### Author: ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)
#### Post date: [November 8, 2020, 11:45pm UTC](https://discourse.julialang.org/t/converting-from-24-bit-image-as-byte-array-to-rgb/49806/2 "2020-11-08T23:45:44Z")

</div>

How about

```julia
im2 = reinterpret(RGB{N0f8}, rc)

```

---

<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: [November 9, 2020, 1:38am UTC](https://discourse.julialang.org/t/converting-from-24-bit-image-as-byte-array-to-rgb/49806/3 "2020-11-09T01:38:30Z")

</div>

Or `colorview(RGB, normedview(img))` from ImageCore.

---

<div class="post-metadata">

### Author: ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)
#### Post date: [November 9, 2020, 8:45am UTC](https://discourse.julialang.org/t/converting-from-24-bit-image-as-byte-array-to-rgb/49806/4 "2020-11-09T08:45:17Z")

</div>

Thank you, [contradict](https://discourse.julialang.org/u/contradict) & [tim.holy](https://discourse.julialang.org/u/tim.holy)

```julia
im2 = reinterpret(RGB{N0f8}, r)

```

produce something, but it wouldn’t display as an image.

```julia
im2 = colorview(RGB{N0f8}, r)

```

would work, though producing some complicated type:

```julia
Base.ReshapedArray{RGB{Normed{UInt8,8}},2,Base.ReinterpretArray{RGB{Normed{UInt8,8}},3,UInt8,SubArray{UInt8,3,Array{UInt8,3},Tuple{ImageCore.ColorChanPerm{3},Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}}},false}},Tuple{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64}}}

```

and

```julia
colorview(RGB, normedview(r))

```

appears the best and generic solution.
