Skip to content

Instantly share code, notes, and snippets.

Kevin Mader kmader

  • Magic Leap
  • Zurich, Switzerland
View GitHub Profile
@kmader
kmader / gist:8854664
Last active Aug 29, 2015
SparkR with CSV Data
View gist:8854664
library(SparkR,lib.loc="/home/mader/tools/SparkR-pkg/lib")
sc<-sparkR.init(master="local[40]")
cfile<-textFile(sc,"/home/mader/work/simple.csv")
testinput<-take(cfile,3)
headertext<-strsplit(testinput[[1]],",")[[1]]
sample.col<-which(headertext %in% "file.name")
format.row<-function(in.row) {
in.txt<-strsplit(in.row,",")[[1]]
list(in.txt[sample.col],mapply(list,headertext[-sample.col],sapply(in.txt[-sample.col],as.double))[2,])
}
@kmader
kmader / AverageSliceValue.java
Created Mar 5, 2014
ImageJ plugin which calculates the average value in each slice
View AverageSliceValue.java
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;
public class AverageSliceValue implements PlugIn {
public void run(String arg) {
@kmader
kmader / AverageSliceValue.py
Created Mar 5, 2014
Calculate the average value in each slice
View AverageSliceValue.py
image = WindowManager.getCurrentImage()
stack = image.getStack() # get the stack within the ImagePlus
n_slices = stack.getSize() # get the number of slices
# iterate over every slice
for sliceIndex in range(1,n_slices+1):
curSlice=stack.getProcessor(sliceIndex)
sumVal=0;countPixel=0
# iterate over every pixel in the slice
for cPixel in curSlice.toFloatArrays()[0]:
sumVal+=cPixel
@kmader
kmader / Download and Setup
Last active Aug 29, 2015
Exercise 4 Setup and K-Means Code
View Download and Setup
% change to your home directory
cd('~')
% download and extract the latest version of fiji
unzip('http://jenkins.imagej.net/job/Stable-Fiji/lastSuccessfulBuild/artifact/fiji-nojre.zip','./')
% add the Fiji scripts folder to the matlab path
addpath 'Fiji.app/scripts'
% start Miji
Miji
% for some reason Miji changes to directory so go back to the home directory
cd('~')
@kmader
kmader / Shape Analysis with FIJI
Last active Aug 29, 2015
Some of the starting code for exercises related to the Single Object Analysis
View Shape Analysis with FIJI
% start Fiji interface
cur_dir=pwd;
Miji
% for some reason the miji script changes directory so this changes it back
cd(cur_dir);
% create the simulated image
[outImage,out_pos,out_shape,out_theta] = cell_simulator(100,10,3,0,1);
% send the image to FIJI
MIJ.createImage('test',outImage,true);
% set a threshold (yes the programmer spelled it incorrectly)
@kmader
kmader / Show Slices and Isosurface in Matlab
Last active Aug 29, 2015
Loads images from ImageJ/FIJI and shows a histogram, plots slices and creates an isosurface
View Show Slices and Isosurface in Matlab
% load the sample image
MIJ.run('Confocal Series (2.2MB)');
stackImage = double(MIJ.getCurrentImage);
% show a slice
imagesc(stackImage(:,:,25));pause(2);
% show a histogram of the image
hist(stackImage(stackImage>0));pause(2);
% create slices
xv=[1,200,400];
yv=xv;
@kmader
kmader / Matlab Shape Analysis Function
Last active Aug 29, 2015
The starting point for a matlab function to perform shape analysis and fitting an ellipse to your data
View Matlab Shape Analysis Function
% this function (will) performs the ellipsoid based shape analysis on a 3D image
% the input is a labeled image probably from the bwlabel function
% the output is an array formatted like such
% labelId, volume, centerX, centerY, centerZ, extentsX, extentsY, extentsZ, pca1X, pca1Y, pca1Z, score1, score2, score3
function [out_table]=ellipse_analysis(in_image)
% create an array the same size as the image of x,y, and z points. This way we can calculate
% center of volume and other parameters by using multiplication
[xgrid,ygrid,zgrid]=meshgrid(1:size(in_image,1),1:size(in_image,2),1:size(in_image,3));
num_of_obj=max(in_image(:));
@kmader
kmader / CreateMeshStateFile
Last active Aug 29, 2015
Create a mesh in Paraview
View CreateMeshStateFile
<ParaView>
<ServerManagerState version="4.1.0">
<Proxy group="animation" type="AnimationScene" id="263" servers="16">
<Property name="AnimationTime" id="263.AnimationTime" number_of_elements="1">
<Element index="0" value="0"/>
</Property>
<Property name="Caching" id="263.Caching" number_of_elements="1">
<Element index="0" value="0"/>
<Domain name="bool" id="263.Caching.bool"/>
</Property>
@kmader
kmader / curvature_script.m
Last active Aug 29, 2015
Compute Curvatures and Examine Results (in 2D)
View curvature_script.m
% Read the starting image into Matlab
bwData=MIJ.getCurrentImage > 0;
%% setup and run curvature
% calculate the labels
labelImage=bwlabel(bwData);
% Calculate the Curvatures
MIJ.run('Compute Curvatures','compute sigma=2 use order')
% Read the output image into Matlab as a Stack
curvData=MIJ.getCurrentImage;
@kmader
kmader / extract_skeleton.m
Created Mar 26, 2014
Extract Skeleton From Image
View extract_skeleton.m
distSkel=MIJ.getCurrentImage;
% transform to a list
[xx,yy,zz]=meshgrid(1:size(distSkel,1),1:size(distSkel,2),1:size(distSkel,3));
% find the non zero values inside objects
nonZeroPts=find(distSkel>0);
skelList=[xx(nonZeroPts) yy(nonZeroPts) zz(nonZeroPts)];
You can’t perform that action at this time.