Skip to content

Instantly share code, notes, and snippets.

View kmader's full-sized avatar

Kevin Mader kmader

  • Zurich, Switzerland
View GitHub Profile
@kmader
kmader / recoTools.R
Last active December 31, 2015 11:29
Shiny Beamline Interface
library(tiff)
library(gdata)
# path paste
pa.paste<-function(...) paste(...,sep="/")
get.last<-function(in.list,offset=0) in.list[length(in.list)-offset]
pa.getlast<-function(in.path,offset=0) get.last(strsplit(in.path,"/")[[1]],offset=offset)
get.or.blank<-function(var,altval="") {
if(is.null(var)) altval
else var
}
@kmader
kmader / gist:8854664
Last active August 29, 2015 13:56
SparkR with CSV Data
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.py
Created March 5, 2014 15:46
Calculate the average value in each slice
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 / AverageSliceValue.java
Created March 5, 2014 15:56
ImageJ plugin which calculates the average value in each slice
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 / Download and Setup
Last active August 29, 2015 13:57
Exercise 4 Setup and K-Means Code
% 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 August 29, 2015 13:57
Some of the starting code for exercises related to the Single Object Analysis
% 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 / Matlab Shape Analysis Function
Last active August 29, 2015 13:57
The starting point for a matlab function to perform shape analysis and fitting an ellipse to your data
% 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 / Show Slices and Isosurface in Matlab
Last active August 29, 2015 13:57
Loads images from ImageJ/FIJI and shows a histogram, plots slices and creates an isosurface
% 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 / CreateMeshStateFile
Last active August 29, 2015 13:57
Create a mesh in Paraview
<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 August 29, 2015 13:57
Compute Curvatures and Examine Results (in 2D)
% 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;