# Display image as Array{UInt8, 4}: in julia

**URL:** <https://discourse.julialang.org/t/display-image-as-array-uint8-4-in-julia/103924>\
**Category:** General Usage\
**Tags:** images, image-processing\
**Created:** [September 16, 2023, 8:31am UTC](https://discourse.julialang.org/t/display-image-as-array-uint8-4-in-julia/103924 "2023-09-16T08:31:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hungpham3112](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hungpham3112/32/34315_2.png) [@hungpham3112](https://discourse.julialang.org/u/hungpham3112)\
**Post date:** [September 16, 2023, 8:31am UTC](https://discourse.julialang.org/t/display-image-as-array-uint8-4-in-julia/103924/1 "2023-09-16T08:31:02Z")

</div>

I load the dataset from h5 file with HDF5.jl to work with binary classifying problems with neural networks

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/6/d63e3aa4ef63de4fc47c822a555c47c90bec4d81.png)

I want to display an image from

```julia
train_set_x
3×64×64×209 Array{UInt8, 4}:

```

Element type of this array is UInt8 but when I show it, it returns as hex but not decimal

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/f/9fb15989cb0c2f803c592512b61e19f6cdc9cd12.png)

I had a look at [this answer](https://discourse.julialang.org/t/how-to-display-an-array-of-uint8-as-a-color-image/93990) but the code didn’t work for me. Python seems user-friendly than Julia when display an Image from array

```julia
plt.imshow(train_set_x_orig[index])

```

Why array in hex not in decimal? What is the most user-friendly way to display array as an image? Thank you.

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [September 16, 2023, 9:29am UTC](https://discourse.julialang.org/t/display-image-as-array-uint8-4-in-julia/103924/2 "2023-09-16T09:29:44Z")

</div>

You need to convert to colors first. Images.jl has a convenience function `colorview` for that. See [Quickstart · JuliaImages](https://juliaimages.org/latest/tutorials/quickstart/#Converting-between-colorants-and-separate-color-channels)

Note that `Y` here, doesn’t make a copy of `X`, but merely reinterprets the original array as colors.  
Jupyter, Pluto and VSCode know how to display colors:

![image](https://global.discourse-cdn.com/julialang/original/3X/9/5/95ccffe5fa51fc491b92529a2ded6272b715f2d6.png)

Edit: Sorry, I’ve missed that you were already using colorview in your code. The point is that you need to provide a number format for RGB, in this case N0f8 is appropriate.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 16, 2023, 9:36am UTC](https://discourse.julialang.org/t/display-image-as-array-uint8-4-in-julia/103924/3 "2023-09-16T09:36:55Z")

</div>

It’s not clear to me if you want it displayed as an image or as a numerical array. If as image, se previous post, if as numerical array, you can just convert to `Int` by typing

```julia
Int.(train_set_x)

```

---

<div class="post-metadata">

**Author:** ![hungpham3112](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hungpham3112/32/34315_2.png) [@hungpham3112](https://discourse.julialang.org/u/hungpham3112)\
**Post date:** [September 16, 2023, 11:03am UTC](https://discourse.julialang.org/t/display-image-as-array-uint8-4-in-julia/103924/4 "2023-09-16T11:03:25Z")

</div>

I solved the problem with your suggestion

```julia
raw_img = train_set_x[:, :, :, :]
img_perm = colorview(RGB{N0f8}, raw_img)
transposed_img = permutedims(img_perm, (2, 1, 3))
# imrotate(img_perm, π/2)|
mosaicview(transposed_img[:, :, 1:20], nrow=4, ncol=5)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/5/e53eb64036f2c35718c77e73d38bd9ed3f916371.jpeg)

The h5 file come from python code and I translate to julia. The dimension order in julia (3, 64, 64) a lil bit different to numpy array (64, 64, 3), I don’t know why Images.jl choose this, but now I learned about permutedims so it’s ok.
