Skip to content

Instantly share code, notes, and snippets.

View jnkather's full-sized avatar

Jakob Nikolas Kather jnkather

View GitHub Profile
@jnkather
jnkather / stairstep_array.m
Last active August 29, 2015 14:21
Create a 1D or 2D stairstep array in Matlab
% (c) Jakob Nikolas Kather 2015
% contact: http://www.kather.me
% aim is to create a 1D-stairstep array, i.e. transform
% 1 2 3 4 to
% 1 1 1 2 2 2 3 3 3 4 4 4
matrix = 1:4
newSize = 3
step_matrix = reshape(repmat(matrix,newSize,1),1,[])
@jnkather
jnkather / hex2rgb.m
Last active August 29, 2015 14:21
Convert hexadecimal color string to RGB values in Matlab
% (c) Jakob Nikolas Kather 2015
% contact: http://www.kather.me
function rgb = hex2rgb(hexString)
if size(hexString,2) ~= 6
error('invalid input: not 6 characters');
else
r = double(hex2dec(hexString(1:2)))/255;
g = double(hex2dec(hexString(3:4)))/255;
b = double(hex2dec(hexString(5:6)))/255;
@jnkather
jnkather / analyze_pixel_colors_OD.m
Last active August 29, 2015 14:21
Analyze colors of histological image in OD space
% (c) Jakob Nikolas Kather 2015
% contact: http://www.kather.me
% this code uses a histological image and performs the following steps
% - convert to optical density (OD) space (ref: Ruifrok et al. http://www.ncbi.nlm.nih.gov/pubmed/11531144)
% - plot image pixels in OD space
% - color pixels according to their original color
% this script can be used to visualize the color distribution of a given histological image
% get source image
@jnkather
jnkather / plotPlane.m
Last active August 29, 2015 14:21
Plot a plane through 3 points
% (c) Jakob Nikolas Kather 2015
% contact: http://www.kather.me
% this function plots a plane through the points x,y,z in a 3D plot
function normal = plotPlane(x,y,z)
% plot triangle through x y z, optional
% fill3([x(1),y(1),z(1)],[x(2),y(2),z(2)],[x(3),y(3),z(3)],'b')
@jnkather
jnkather / thesis-build
Last active August 29, 2015 14:21
Build a Latex document
#!/bin/bash
cd ~/BitBucket/master-thesis/
pdflatex main.tex
bibtex main
pdflatex main.tex
echo '######### last run #########'
pdflatex main.tex
open main.pdf
open main.log
exit
@jnkather
jnkather / manuscript-build
Created May 22, 2015 13:06
Markdown to PDF with citations
pandoc --filter pandoc-citeproc -s main.md -o main.pdf --bibliography=library.bib
@jnkather
jnkather / rgb_color_cube.m
Last active August 29, 2015 14:21
Show the RGB gamut in CIELAB space
% JN Kather, 2015
% Show the RGB gamut in CIELAB space
figure();
[X,Y,Z] = meshgrid(linspace(0,1,25));
colors = ([X(:),Y(:),Z(:)]);
colorsLAB = rgb2lab(colors);
scatter3(colorsLAB(:,1),colorsLAB(:,2),colorsLAB(:,3),100,colors,'filled');
@jnkather
jnkather / CIELAB_color_cube.m
Last active August 29, 2015 14:21
Show a CIELAB color cube composed of 15^3 balls
% JN Kather, 2015
% Show a CIELAB color cube composed of 25^3 balls
% note: Matlab CIELAB colorspace goes approx. from -108 to +100 as measured
% with: colors = rgb2lab(jet(100)); min(colors(:)), max(colors(:))
figure();
[X,Y,Z] = meshgrid(linspace(-108,100,15));
colors = lab2rgb([double(X(:)),double(Y(:)),double(Z(:))]);
scatter3(X(:),Y(:),Z(:),100,colors,'filled');
xlabel('L'); ylabel('a'); zlabel('b');
axis equal tight
@jnkather
jnkather / distance-2D.m
Created May 27, 2015 18:46
calculate distance from a given point for a cloud of points, 2D
% JN Kather 2015
% calculate distance from a given point for a cloud of points, 2D
% cloud of points
Pts = rand(500,2);
% calculate distance from P(px|py)
px = 0.5; py = 0.5
distance = sqrt((Pts(:,1)-px).^2 + (Pts(:,2)-py).^2);
@jnkather
jnkather / distance-3D.m
Last active August 29, 2015 14:22
calculate distance from a given point for a cloud of points, 3D
% JN Kather 2015
% calculate distance from a given point for a cloud of points, 3D
% cloud of points
Pts = rand(10000,3);
% calculate distance from P(px|py|pz)
px = 0.5; py = 0.5; pz = 0.5;
distance = sqrt( (Pts(:,1)-px).^2 + ...
(Pts(:,2)-py).^2 + ...