How do I turn array data into an image?

I’m just trying julia from MATLAB, in which it was quite intuitive to download arrays and display them as images (imshow worked without issue mostly and there was the imagesc function when an array needed to be scaled). However, I have been unable to find out how to do this in Julia.

I have a 128x128 array of UInt16 values, corresponding to pixels. I have loaded the Images.jl package but I cannot figure out how to display this array, Julia keeps returning it as an array and when I call imshow it says that imshow is not defined. Has this function been replaced? As far as I can tell Images is being loaded without issue.

Thanks

2 Likes

You need one of the plotting packages. Install Plots.jl or PyPlot.jl or… the function to call maybe called a bit different, but the docs will tell you. Also, as a word of “warning”, plotting tends to be quite slow for the first plot (but fast afterwards). If you wonder why, search “time to first plot”.

(and welcome to Julia!)

3 Likes

Being in medical imaging, displaying images in code is a common use case for me. I also found the analog from Matlab/Python confusing, but I’m so hooked on everything else Julia this is now only a minor disturbance. I found the heatmap function in Plots.jl and imshow in ImageView.jl to serve my particular needs.

6 Likes

I am also in medical imaging and more or less am in the same situation. I have tried the route of using ImageView but it returned an error when I tried to install it. I will try heatmaps now.

UPDATE: heatmaps worked, thanks!

1 Like

You’ll probably find that heatmap(I, color=:grays, aspect_ratio=1) useful then. Enjoy!

4 Likes

In a Jupyter notebook, things like using Colors; Gray.(matrix) and colorview(RGB, array3) should show images inline. (IIRC there are ways to make this happen in a sufficiently fancy terminal too, rather than in a plot window.)

In addition to the plotting packages, try ImageView or the remarkable ImageInTerminal:

If you have UInt16 data you might read https://juliaimages.org/latest/quickstart/#The-0-to-1-intensity-scale-1 and https://juliaimages.org/latest/arrays_colors/#fixedpoint-1 (use N0f16).

3 Likes

For a great alternative to ImageInTerminal, if you have a Mac with iTerm2, check out TerminalExtensions.jl from Keno. Then you’ll have full-resolution images in your terminal. Hard to find, but worth it.

But for more sophisticated display, ImageView is really great!

1 Like

Or https://github.com/simonschoelly/KittyTerminalImages.jl on Linux.

1 Like

I was hoping to do this and have tried, but unfortunately was not able to install ImageView :frowning: (Have posted this in a thread but it as of yet is unresolved: Error installing ImageView Library - #4 by samantp)

Hi, one last thing, the heatmap plot sucessfully displayed the image, however is there a way for me to also save the file as a .tiff? I have a bunch of dicom files that I’d like to extract the images from and save them as .tiffs to make them easier to deal with basically.