Skip to content

Instantly share code, notes, and snippets.

View jnkather's full-sized avatar

Jakob Nikolas Kather jnkather

View GitHub Profile
@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 / 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 / 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 / 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 / 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);
@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 / 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 + ...
@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 / 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 / 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');