using NIfTI, Tk, Images, ImageView
function mriview(ni::NIVolume, xy=["x", "z"], zoom::Int=5)
img = Image(ni.raw, ["spatialorder" => ["x", "y", "z"], "timedim" => 4, "colorspace" => "Gray",
"pixelspacing"=>voxel_size(ni.header)])
img = scale(scaleminmax(img), img)
imgc, imgslice = display(img, xy=xy)
tksize = get_size(toplevel(imgc))
controlheight = tksize[2] - size(img, xy[2])
set_size(toplevel(imgc), max(tksize[1], size(img, xy[1])*zoom),
size(img, xy[2])*zoom+controlheight)
(imgc, imgslice)
end
mriview(path::String) = mriview(niread(path, mmap=true))
No more. Something must have changed in the api?
Any ideas?
We need the image file that causes your code to fail, along with the stack trace.
Thanks, Uwe. But my idea was to see if anyone was already using the combo (Tk + Images + ImageView) and could spot the problem at first sight. If you (or anyone else) are not familiar with this, don’t disturb yourself over it. (The problem is the Image no longer takes the arguments indicated – the API must have changed. It is not clear how to use it from the documentation.)
pasting your original question into AI it says this relies on several deprecated and pre-1.0 apis, and suggested the following
using NIfTI
using Images
using ImageView
"""
mriview(path::String)
Reads a NIfTI file and opens an interactive ImageView window.
"""
function mriview(path::String)
# 1. Read the volume using memory mapping for efficiency
ni = niread(path, mmap=true)
# 2. Extract the raw numerical array
raw_data = ni.raw
# 3. Normalize the data to [0, 1] for visual display
# MRI data is often stored as Int16 or Float32 with arbitrary ranges
min_val = minimum(raw_data)
max_val = maximum(raw_data)
range_val = max_val > min_val ? (max_val - min_val) : 1.0
# Broadcast normalization and cast to the Gray colorspace
img_gray = Gray.((raw_data .- min_val) ./ range_val)
# 4. Display the image
# imshow returns a dictionary containing the GTK window state and canvas
guidict = imshow(img_gray)
return guidict
end
maybe that is a useful starting point?
That is good, thanks, but the input is a 3d image. I knew how to load the data: the problem was Tk’s Image. I tried Copilot, but it did not work.