# Convert Array{UInt32, 2} to ARGB image with Images.jl

**URL:** <https://discourse.julialang.org/t/convert-array-uint32-2-to-argb-image-with-images-jl/50822>\
**Category:** Visualization\
**Created:** [November 26, 2020, 4:06pm UTC](https://discourse.julialang.org/t/convert-array-uint32-2-to-argb-image-with-images-jl/50822 "2020-11-26T16:06:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wrgr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wrgr/32/2796_2.png) [@wrgr](https://discourse.julialang.org/u/wrgr)\
**Post date:** [November 26, 2020, 4:06pm UTC](https://discourse.julialang.org/t/convert-array-uint32-2-to-argb-image-with-images-jl/50822/1 "2020-11-26T16:06:00Z")

</div>

How to convert Array{UInt32, 2} to ARGB image with Images.jl?

---

<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:** [November 26, 2020, 7:46pm UTC](https://discourse.julialang.org/t/convert-array-uint32-2-to-argb-image-with-images-jl/50822/2 "2020-11-26T19:46:56Z")

</div>

```julia
julia> reinterpret(ARGB{N0f8}, rand(UInt32, 3, 2))
3×2 reinterpret(ARGB{N0f8}, ::Array{UInt32,2}):
 ARGB{N0f8}(0.569,0.341,0.922,0.075) ARGB{N0f8}(0.239,0.31,0.69,0.192)
 ARGB{N0f8}(0.153,0.761,0.208,0.149) ARGB{N0f8}(0.486,0.769,0.282,0.78)
 ARGB{N0f8}(0.09,0.427,0.765,0.482) ARGB{N0f8}(0.733,0.443,0.616,0.518)

```

Note that you may want to `collect` the reinterpreted array before further processing:

```julia
julia> RA = reinterpret(ARGB{N0f8}, rand(UInt32, 512, 512));

julia> A = collect(RA);

julia> using Statistics, BenchmarkTools

julia> @btime mean($RA)
  2.528 ms (0 allocations: 0 bytes)
ARGB{Float32}(0.49983406f0,0.500403f0,0.4998448f0,0.50037414f0)

julia> @btime mean($A)
  81.999 μs (0 allocations: 0 bytes)
ARGB{Float32}(0.4998341f0,0.50040305f0,0.4998448f0,0.5003742f0)

```

---

<div class="post-metadata">

**Author:** ![wrgr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wrgr/32/2796_2.png) [@wrgr](https://discourse.julialang.org/u/wrgr)\
**Post date:** [November 27, 2020, 7:53am UTC](https://discourse.julialang.org/t/convert-array-uint32-2-to-argb-image-with-images-jl/50822/3 "2020-11-27T07:53:05Z")

</div>

Thank you, it works!
