Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View vfmatzkin's full-sized avatar

Franco Matzkin vfmatzkin

View GitHub Profile
@vfmatzkin
vfmatzkin / fsl-installation-in-google-colab.ipynb
Last active April 3, 2024 22:35
FSL installation in Google colab
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vfmatzkin
vfmatzkin / SimpleElastixConda.md
Created July 2, 2021 14:49
Install SimpleElastix on a conda env

I've decided to create this article because I've continously followed the official and alternative tutorials around the internet with no luck. Anyway, this last one was the closest, so some steps will be the same.

This process was done in Ubuntu 20.04 LTS, and covers only SimpleElastix wrapping for Python 3.

If you use a platform such as Anaconda or virtualenv, you will have to deactivate them (conda deactivate) before compiling SimpleElastix, and once it's compiled activate it before the last step (I'll do this in this tutorial). If you activate them before that step, the SimpleElastix SuperBuild will skip some steps and then the instalation may fail. With deactivating I refer also to the base environment, your terminal must look as before installing anaconda or virtualenv.

Also you have to uninstall SimpleITK if you have it already installed (otherwise you will end up

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vfmatzkin
vfmatzkin / brabandere_loss.py
Created September 1, 2021 01:57
Implementation of the Brabandere Loss term, used in https://arxiv.org/abs/1708.02551
def brabandere_loss(pred, alpha=1, beta=1, gamma=1e-3, dv=.05, dd=2):
"""
Implementation of the proposed loss in:
Semantic Instance Segmentation with a Discriminative Loss Function (https://arxiv.org/abs/1708.02551)
in which, the loss is a sum of three terms:
1) A intra-cluster attraction force.
2) A inter-cluster repealling force.
3) A regularization term for the mean codes.
This loss in unsupervised, so only batches of codes for each cluster are needed.
@vfmatzkin
vfmatzkin / antspy.py
Created March 16, 2021 02:48
I can't believe ANTs is that good in Python
# Script written by Franco Matzkin (with the great help of this amazing tool)
# Install ANTsPy with:
# pip install antspyx
# (I'm not sure this is the last version).
import ants
moving_ct_path = 'imgs/CTimage.nii.gz'
moving_mask_path = 'imgs/CT_brain_mask.nii.gz'
fixed_ct_path = 'imgs/Atlas.nii.gz'
@vfmatzkin
vfmatzkin / fsl_registration.py
Last active March 15, 2021 15:58
FSL FLIRT Registration with Python & SimpleITK
# Created by Franco Matzkin (vfmatzkin [at] gmail.com)
# This gist gives a basic intuition on how to use tmp files to run FSL's FLIRT
# commands with Python and use those images with the help of SimpleITK.
# Info on how to install FLIRT: https://gist.github.com/vfmatzkin/7987a6edf034d28427696e1fabbb2979 #noqa
import os
import shutil
import tempfile
@vfmatzkin
vfmatzkin / some_noises.py
Created February 26, 2021 17:01
Some noises
def salt_and_pepper(img, noise_probability=1, noise_density=0.2, salt_ratio=0.1):
"""
Given a numpy image, return a salt and pepper noised image.
:param img: Image in which noise will be added. The first dimension will be taken as the batch element index.
:param noise_probability: Probability of adding the noise (by default 1).
:param noise_density: Amount of noise in the image (as a percentage).
:param salt_ratio: Ratio of salt (vs pepper) added in the image.
:return: Noised batch of images.
"""
@vfmatzkin
vfmatzkin / inverse-parammap-simpleelastix.py
Created January 19, 2021 13:09
Inverse parametermap calculation using SimpleElastix (SimpleITK extension)
# This gist is a portion of a code that doesn't work. Right now, since I
# cant use SimpleElastix easily, I switched to FSL for registration,
# which has a CLI.
import SimpleITK as sitk
import os
# Inverse parametermap calculation. It gives a SIGSEV error. Check updates in
# SimpleElastix and see if it's solved.
# https://github.com/SuperElastix/SimpleElastix/issues/167