# Convert Array{RGB{Float32},2} to Array{Float32,2}

**URL:** <https://discourse.julialang.org/t/convert-array-rgb-float32-2-to-array-float32-2/64312>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [July 9, 2021, 12:03am UTC](https://discourse.julialang.org/t/convert-array-rgb-float32-2-to-array-float32-2/64312 "2021-07-09T00:03:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![KyleModell](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@KyleModell](https://discourse.julialang.org/u/KyleModell)\
**Post date:** [July 9, 2021, 12:03am UTC](https://discourse.julialang.org/t/convert-array-rgb-float32-2-to-array-float32-2/64312/1 "2021-07-09T00:03:21Z")

</div>

I have an image that is Type: Array{RGB{Float32},2} but need to convert it to Type: Array{Float32,2}. Is there a way to do that ? Thanks!

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 9, 2021, 12:12am UTC](https://discourse.julialang.org/t/convert-array-rgb-float32-2-to-array-float32-2/64312/2 "2021-07-09T00:12:27Z")

</div>

`reinterpret` should do what you want.

---

<div class="post-metadata">

**Author:** ![KyleModell](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@KyleModell](https://discourse.julialang.org/u/KyleModell)\
**Post date:** [July 9, 2021, 12:21am UTC](https://discourse.julialang.org/t/convert-array-rgb-float32-2-to-array-float32-2/64312/3 "2021-07-09T00:21:53Z")

</div>

Thanks Oscar! When I try that the type of object that is returned is:  
Base.ReinterpretArray{Float32,2,RGB{Float32},Array{RGB{Float32},2}}. Is there a way for the type to simply be: Array{Float32,2}? Thanks!

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [July 9, 2021, 1:02am UTC](https://discourse.julialang.org/t/convert-array-rgb-float32-2-to-array-float32-2/64312/4 "2021-07-09T01:02:05Z")

</div>

You can use `collect` to convert most lazy wrapper types in Julia to their concrete representations, including `ReinterpretArray`, `Adjoint`, `SubArray`, etc.

Be aware that reinterpreting a 2D color array of dimensions 2 x 2 will result in an array of size 6 x 2, as the pixel values are unpacked along each column like so:

```julia
[rgb rgb [r r
 rgb rgb] -> g g
              b b
              r r
              g g
              b b]

```

If you want to maintain the original image shape, you’ll probably want to convert the array to grayscale before reinterpreting: `collect(reinterpret(Float32, Gray.(img)))`

---

<div class="post-metadata">

**Author:** ![KyleModell](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@KyleModell](https://discourse.julialang.org/u/KyleModell)\
**Post date:** [July 9, 2021, 1:07am UTC](https://discourse.julialang.org/t/convert-array-rgb-float32-2-to-array-float32-2/64312/5 "2021-07-09T01:07:50Z")

</div>

Brilliant stillyslalom. That worked perfectly. Thanks so much 🙏
