Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yeruoforever opened this issue Nov 24, 2020 · 3 comments
Open

Comments

@yeruoforever
Copy link

yeruoforever commented Nov 24, 2020

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.

@korbinian90
Copy link
Contributor

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.

@yeruoforever
Copy link
Author

yeruoforever commented Nov 25, 2020

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")

@Tokazama
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants