Most users probably want to start with the Images.jl package, which bundles
much (but not all) of the functionality in JuliaImages.
Images (and possibly some additional packages) may be all you need to manipulate images programmatically.
You can install Images.jl via the package manager,
(v1.0) pkg> add Images!!! note
People in some regions such as China might fail to install/precompile Images due to poor network
status. Using proxy/VPN that has stable connection to Amazon S3 and Github can solve this issue.
!!! note
As of Images v0.24.0, ImageIO/ImageMagick IO backends are automatically installed.
If this is your first time working with images in julia, it's likely that you'll need to install some image IO backends to load the images. The current available backends for image files are:
- ImageMagick.jl covers most image formats and has extra functionality. This can be your first choice if you don't have a preference.
- QuartzImageIO.jl exposes macOS's native image IO functionality to Julia. In some cases it's faster than ImageMagick, but it might not cover all your needs.
- ImageIO.jl is a new image IO backend (requires julia >=v"1.3") that provides an optimized performance for PNG files. Check benchmark here
- OMETIFF.jl supports OME-TIFF files. If you don't know what it is, then it is likely that you don't need this package.
These backends aren't exclusive to each other, so if you're a macOS user, you can install all these
backends. And in most cases, you don't need to directly interact with these backends, instead, we
use the save and load provided by the FileIO.jl
frontend. If you've installed multiple backends then FileIO will choose the most appropriate
backend according to your file format. For example, if available ImageIO is used to load PNG
files.
Adding these gives you a basic image IO setup:
(v1.0) pkg> add FileIO ImageMagick ImageIOand to load an image, you can use
using Images, FileIO
using ImageShow # hide
# specify the path to your local image file
img_path = "/path/to/image.png"
img_path = joinpath("assets", "installation", "mandrill.tiff") # hide
img = load(img_path)
To save an image, you can just use save(img_path, img), where save is also provided by FileIO.
When testing ideas or just following along with the documentation, it can be useful to have some images to work with. The TestImages.jl package bundles several "standard" images for you.
(v1.0) pkg> add TestImagesTo load one of the images from this package, say
using TestImages
# backends such as ImageMagick are required
img = testimage("mandrill")When working with images, it's obviously helpful to be able to look at them. If you use Julia through Juno or IJulia, images should display automatically:
Currently there're five julia packages can be used to display an image:
ImageShowis used to support image display in Juno and IJulia. This happens automatically if you areusing Images.ImageInTerminalis used to support image display in terminal.ImageViewis an image display GUI. (For OSX and Windows platforms, Julia at leastv1.3is required)Plotsmaintained by JuliaPlots is a general plotting package that support image display.Makieis also maintained by JuliaPlots but provides rich interactive functionality.
To visualize multiple images in one frame, you can create a bigger image from multiple image sources with mosaicview,
which is an enhanced version of cats.
using Images, TestImages
img1 = testimage("mandrill") # 512*512 RGB image
img2 = testimage("blobs") # 254*256 Gray image
mosaicview(img1, img2; nrow=1)
img = testimage("mri-stack") # 226×186×27 Gray image
mosaicview(img; fillvalue=0.5, npad=2, ncol=7, rowmajor=true)
Reading and writing images, as well as graphical display, involve interactions with external software libraries; occasionally, the installation of these libraries goes badly. Fortunately, the artifact system shipped since Julia 1.3 has made this process much more reliable, so if you're experiencing any installation trouble, please try with Julia 1.3 or higher.
This documentation is generated with the following environment setup. While reading the documentation, if you encounter any errors or if the outputs in your local machine differ from the documentation, you could first check the Julia and package versions you're using. If the error or inconsistency still exists, please file an issue for that; it helps us improve the documentation.
using InteractiveUtils
using Pkg, Dates
today()
versioninfo()
Pkg.status()
