WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Add example code for removing data from imaging files while retaining headers #517

@tsalo

Description

@tsalo

This seems more useful to me than having 0B files.

@effigies showed me how to do this for NIfTIs (see Python code below) but we should have documentation on how to do it for a range of common imaging filetypes in the CONTRIBUTING file.

import io
import gzip
from pathlib import Path

import nibabel as nb

path = Path('/path/to/example/dset').resolve()
for file in path.rglob('*.nii.gz'):
    img = nb.load(file)
    bio = io.BytesIO()
    img.header.write_to(bio)
    header = bio.getvalue()
    # Write gzipped header for .nii.gz files
    with gzip.open(file, 'wb') as f:
        f.write(header)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions