Sane microscopy image labeling in Julia
This is collection of simple labeling functions specifically suited for quickly embedding labels in microscopy images. I'm hoping to cover common use-cases like adding timestamps, scalebars, transitions, and extra image details.
Example
Say you have a OME-TIFF with lots of useful metadata exposed via OMETIFF.jl
:
using FileIO, ImageShow, AxisArrays
using Unitful: μm
using MicroscopyLabels
img = load(normpath(@__DIR__, "assets", "example.ome.tif"))
Gray ImageMeta with: data: 3-dimensional AxisArray{Gray{N0f16},3,...} with axes: :y, (0.0:1.3036:666.1396000000001) μm :x, (0.0:1.3036:666.1396000000001) μm :time, (0.0:10.0:890.0) s And data, a 512×512×90 reshape(reinterpret(Gray{N0f16}, ::Array{UInt16,6}), 512, 512, 90) with eltype ColorTypes.Gray{FixedPointNumbers.Normed{UInt16,16}} properties: Description: Elapsed_Times: Unitful.Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}}[NaN s, NaN s, NaN s, NaN s, NaN s, NaN s, NaN s, NaN s, NaN s, NaN s … NaN s, NaN s, NaN s, NaN s, NaN s, NaN s, NaN s, NaN s, NaN s, NaN s]
Any fully annotated AxisArray
object should work here, including the output from NRRD.jl
, not just OMETIFF.jl
MicroscopyLabels.jl
lets you rapidly and accurately annotate the image by reading the internal metadata directly:
scalebar!(img, 50μm)
timestamp!(img)
# lets look at the 30th frame real quick:
view(img, Axis{:time}(30))
Reference
MicroscopyLabels.label_particles!
— Methodlabel_particles!(img, labels)
Writes text labels generated by ImageMorphology.label_components
into img
. Writes one text label per centroid identified by ImageMorphology.component_centroids
. Ignores the background pixels, i.e. anything labeled with 0.
Example
using MicroscopyLabels
using AxisArrays
using ImageMorphology
# create a 50x50x1 YXT image with one spot
img = AxisArray(zeros(50, 50, 1), Axis{:y}(1:50), Axis{:x}(1:50), Axis{:time}(1:1));
img[10:12, 10:12, 1:1] .= 1.0;
# assign labels using ImageMorphology.label_components
labels = AxisArray(label_components(img .!== 0.0), AxisArrays.axes(img));
label_particles!(img, labels)
MicroscopyLabels.scalebar!
— Methodscalebar!(img, len; fontsize)
Add a scalebar len
long in the bottom left of img
along the x axis with text of size fontsize
given as a fraction of the smallest spatial axis.
Example
using Unitful: μm
using AxisArrays
using MicroscopyLabels
tmp = AxisArray(zeros(200, 200), Axis{:y}(1μm:1μm:200μm), Axis{:x}(1μm:1μm:200μm));
scalebar!(tmp, 25μm, fontsize=0.06)
MicroscopyLabels.timestamp!
— Methodtimestamp!(img; units)
Writes the timestamp in the upper left corner of a multidimensional image img
with the units units
. Images are required to have at least the x
, y
, and time
axes labeled, i.e. img
should be or contain an AxisArray
object with xyt axes. If additional axes are present, the timestamp will be written to all of them.
Simple example
using AxisArrays
using MicroscopyLabels
tmp = AxisArray(zeros(200, 200, 5), Axis{:x}(1:200), Axis{:y}(1:200), Axis{:time}(1:5))
timestamp!(tmp)
Unitful example
We can also add units to the time axis and have these be embedded in the image
using Unitful: s, minute
tmp = AxisArray(zeros(200, 200, 5), Axis{:x}(1:200), Axis{:y}(1:200),
Axis{:time}(0s:45.0s:180s))
# convert the units to minutes
timestamp!(tmp, units=minute)