Skip to content

Instantly share code, notes, and snippets.

View jnkather's full-sized avatar

Jakob Nikolas Kather jnkather

View GitHub Profile
@jnkather
jnkather / sort_by_hue.m
Created June 8, 2015 12:28
Sort a Hex color vector by hue
% JN Kather 2015
% sorts a vector of hex colors by hue
% dependencies: needs functions rgb2hex and hex2rgb
dataDir = 'input/data/';
% read color vector
colorList = readtable(strcat(dataDir,'/custom_color_list3.txt'),...
'ReadVariableNames',false);
@jnkather
jnkather / rotating_cubes.matlab
Created July 22, 2015 17:22
Show the RGB gamut in RGB space and CIELAB space, then rotate the cubes and save the frames as image files
% JN Kather, 2015
% Show the RGB gamut in RGB space and CIELAB space, then
% rotate the cubes and save the frames as image files to
% a subfolder ./output
% set parameters
turns = 1; % how often should the viewpoint turn, default 1
balls = 70; % how many balls to plot
nSteps = 40; % how many viewpoints?, default 40
saveOutput = false; % save output to files? default false
@jnkather
jnkather / showTree.matlab
Created July 22, 2015 19:58
Draw a tree on the current axes. Can be used to visualize spatial datasets as groups of trees.
function showTree( x,y,scale,varargin )
xsize = 0.01*scale;
ysize = 0.03*scale;
radius = 0.03*scale;
treeColor = [0,150,10]/255;
% override tree color
if nargin>3
treeColor = varargin{1}
@jnkather
jnkather / PlotTreeData.matlab
Last active August 29, 2015 14:25
Create a random dataset and show the points as trees.
% requires showTree.m
% --- create data
nObj = 100;
rng(3);
scale = 100;
data = rand(nObj,2)*scale;
% --- set up parameters
saveOutput = true;
@jnkather
jnkather / matlab_block_resize.m
Created October 15, 2015 09:19
create thumbnails of large images using Matlab blockproc and parallel processing
IMpath = 'C:\folder\input\'; % specify input/output folder
allImgs = {'filename1.tif',...
'filename2.tif'}; % specify filenames
% iterate through all images
for i=1:numel(allImgs)
fun = @(block_struct) imresize(block_struct.data,0.1);
imgOut = blockproc([IMpath,char(allImgs{i})],...
[1000 1000],fun,...
'UseParallel',true,...
@jnkather
jnkather / rgb2hex.m
Created June 8, 2015 12:28
Convert RGB color vector to hexadecimal code
% (c) JN Kather 2015
function hex = rgb2hex(rgb)
% expects a vector of three elements of RGB color values between 0 and 1.
% Returns a string containing the hex code of the color.
r = uint8(rgb(1)*255);
g = uint8(rgb(2)*255);
b = uint8(rgb(3)*255);