Option yflip

Examples illustrating the yflip option in the Julia package MIRTjim.

This page comes from a single Julia file: 2-yflip.jl.

You can access the source code for such Julia documentation using the 'Edit on GitHub' link in the top right. You can view the corresponding notebook in nbviewer here: 2-yflip.ipynb, or open it in binder here: 2-yflip.ipynb.

Setup

Packages needed here.

using MIRTjim: jim, prompt
using ImageGeoms: ImageGeom
using ImagePhantoms: shepp_logan, SheppLoganEmis, phantom
using InteractiveUtils: versioninfo

The following line is helpful when running this file as a script; this way it will prompt user to hit a key after each figure is displayed.

isinteractive() ? jim(:prompt, true) : prompt(:draw);

Simple 2D image and 3D stack of images

i1 = shepp_logan(128, SheppLoganEmis()) # 2D image
i1 = i1[12:117,:] # non-square for illustration
i2 = cat(dims=3, i1, 2i1, 3i1)/3 # 3D stack of images
size(i2)
(106, 128, 3)

This figure illustrates how the yflip option affects the image orientation in the "usual" case where y=1:N. This is a typical convention in "image processing" of digital images that lack any physical coordinates for their axes.

ji = (args...; kwargs...) ->
 jim(args...; size=(700,400), kwargs..., prompt=false)
jim(
    ji(i1, "2D default"),
    ji(i1, yflip=false, "2D yflip=false"),
    ji(i1, yflip=true, "2D yflip=true"),
    ji(i2, ncol=2, "3D default"),
    ji(i2, ncol=2, yflip=false, "3D yflip=false"),
    ji(i2, ncol=2, yflip=true, "3D yflip=true"),
)
Example block output

2D image and 3D stack of images with specified x,y coordinates

Now consider the case where we think of the image as a function f(x,y) in the typical case where 0,0 is in the "center" of the image. This convention is more common in physics-based imaging and inverse problems where the image axes have meaningful values (and often have units).

objects = shepp_logan(SheppLoganEmis(); fovs=(120,120))
ig = ImageGeom(dims=(50,64), deltas=(2,2), offsets=(0.5,0.5))
ax = axes(ig)
i3 = phantom(ax..., objects)
i4 = cat(dims=3, i3, 2i3, 3i3) # 3D stack of images

jim(
    ji(ax, i3, "2D default", xlabel="x", ylabel="y"),
    ji(ax, i3, yflip=false, "2D yflip=false"),
    ji(ax, i3, yflip=true, "2D yflip=true"),
    ji(ax, i4, ncol=2, "3D default"),
    ji(ax, i4, ncol=2, yflip=false, "3D yflip=false"),
    ji(ax, i4, ncol=2, yflip=true, "3D yflip=true"),
    prompt = false, gui = true,
)
Example block output

In both cases the "default" option for yflip has the typical desired behavior, but one can modify the default to achieve other behaviors.

Reproducibility

This page was generated with the following version of Julia:

using InteractiveUtils: versioninfo
io = IOBuffer(); versioninfo(io); split(String(take!(io)), '\n')
11-element Vector{SubString{String}}:
 "Julia Version 1.11.1"
 "Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)"
 "Build Info:"
 "  Official https://julialang.org/ release"
 "Platform Info:"
 "  OS: Linux (x86_64-linux-gnu)"
 "  CPU: 4 × AMD EPYC 7763 64-Core Processor"
 "  WORD_SIZE: 64"
 "  LLVM: libLLVM-16.0.6 (ORCJIT, znver3)"
 "Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)"
 ""

And with the following package versions

import Pkg; Pkg.status()
Status `~/work/MIRTjim.jl/MIRTjim.jl/docs/Project.toml`
  [39de3d68] AxisArrays v0.4.7
  [3da002f7] ColorTypes v0.12.0
  [e30172f5] Documenter v1.8.0
  [9ee76f2b] ImageGeoms v0.11.1
  [71a99df6] ImagePhantoms v0.8.1
  [98b081ad] Literate v2.20.1
  [170b2178] MIRTjim v0.25.0 `~/work/MIRTjim.jl/MIRTjim.jl`
  [6fe1bfb0] OffsetArrays v1.14.1
  [91a5bcdd] Plots v1.40.9
  [1986cc42] Unitful v1.21.0
  [b77e0a4c] InteractiveUtils v1.11.0

This page was generated using Literate.jl.