NIfTI.jl icon indicating copy to clipboard operation
NIfTI.jl copied to clipboard

Maybe a function is needed here to just read the header information

Open yeruoforever opened this issue 4 years ago • 3 comments

I am currently analyzing a lung CT data set. A simple task is to obtain the pixel spacing of the image for statistics. When I use niread(), I have to wait for an entire image array to be read from the disk, but The current work only needs to read the header information instead of a complete image array (NIVolume.raw), which seems to take a lot of unnecessary time, especially when this data set contains a lot of cases. A compromise solution is to implement a simple nihread() to read header information. But a better solution is to read only the header information when calling niread(), and only when NIVolume.raw is used the actual array would load from the hard disk into the memory.

yeruoforever avatar Nov 24 '20 07:11 yeruoforever

You can try with

header = niread(fn; mmap=true).header

This opens the data as a memory mapped file, only reading the array from disk, when you actually access it. You can also open larger files than your memory with that. But I'm not sure if it works with compressed files.

korbinian90 avatar Nov 24 '20 09:11 korbinian90

Thanks for your reply, and I tried it.It does not work on gzip files.It throws an error at this line.

if mmap
    if header_gzipped
        close(header_io)
        close(file_io)
        error("cannot mmap a gzipped NIfTI file")

yeruoforever avatar Nov 25 '20 02:11 yeruoforever

We need to separate some of the processes here and have something like niload(f::AbstractString) -> IOMeta and read(::IOMeta) -> AbstractArray. It will take a little reworking because the whole I/O routine is pretty inflexible at the moment.

Tokazama avatar Nov 28 '20 05:11 Tokazama