I have a matrix of Ints. I’m using it for semantic classification so each pixel is a groundtruth label value, e.g.
(10,20)=3 where at coordinate 10,20 there is a pixel value 3 which is the class.
This ground truth label will be used in UNet. I’m wondering how to convert this matrix into a ‘Target Image’ for UNet. I’ve looked at Get an image from a matrix of signed integers `
imadjustintensity(Float64.(gt), extrema(gt))
` but its very indistinguishable for different classes, they are all a shade of similar gray. Could/Should I enhance it? Is there a better way than converting to float?
You can try the AstroImages.jl function imview. It takes any matrix and an optional Color scheme and converts directly to an image without going through Plots. It should have nice normalization by default or you can tweak contrast etc.
If you write a function label_color(label) which takes your labels — whether they start at zero or whatever else — you can convert your integer matrix to a colour matrix with:
img = [label_color(label) for label in gt_mat]
This array comprehension preserves the shape of the matrix, so produces a matrix of colours.
For example, you might use a dictionary:
julia> using Plots: distinguishable_colors
julia> scheme = Dict(0:28 .=> distinguishable_colors(29));
julia> img = [scheme[label] for label in gt_mat];
Using same Plots.jl version, Julia 1.7.3 on Win11, no problem to display such matrix with ~30 million cells:
using Plots; gr(dpi=300)
n = 10
M = rand(1:n, 5041, 6001)
dc = distinguishable_colors(n)
heatmap(M, color=palette(dc,n), framestyle=:none, ratio=1, clims=(0.5,n+0.5))
But with so many pixels it might be difficult to read: