Archive for the ‘Uncategorized’ Category

Read animated gif and convert to rgb frames

Wednesday, June 14th, 2017

Matlab’s built in imread (as of 2017) doesn’t load animated gifs correctly. You can fix this by changing the line:

map = info.ColorTable;

in /Applications/MATLAB_R2017a.app/toolbox/matlab/imagesci/private/readgif.m with

map = reshape([info(:).ColorTable],[],3,n);

For a single frame indexed image you can use ind2rgb to convert to an rgb image. To do this on entire animated gif. You can use an arrayfun for-loop hack:

[X,M] = imread('input.gif');
Y = cell2mat(permute(arrayfun(@(C) ind2rgb(X(:,:,:,C),M(:,:,C)),1:size(X,4),'UniformOutput',false),[1 4 3 2]));

Update:

Use this instead:

map = zeros(0,3,n);
for j = 1:n
  map(1:size(info(j).ColorTable,1),:,j) = info(j).ColorTable;
end

Delete all git branches except current

Saturday, March 18th, 2017
git branch | grep -v "^\\*" | xargs git branch -D 

Matlab imresize with bilinear methods computes different result than bilinear interpolation

Thursday, May 12th, 2016

Strangely, it seems that matlab’s builtin function imresize does not reproduce the usual bilinear interpolation.

Let’s consider a toy 4×4 image:

F = matrixnormalize(magic(4));

input image

BF = imresize(F,[256 256],'bilinear');

imresize bilinear

Compare that to explicitly computing the bilinear interpolation:

[X,Y] = meshgrid(1:size(F,2),1:size(F,1));
[BX,BY] = meshgrid(linspace(1,size(F,2),size(BF,2)),linspace(1,size(F,1),size(BF,1)));
BF2 = interp2(X,Y,F,BX,BY,'bilinear');

imresize bilinear

The difference is obvious in the corners and along the edges. The imresize result has some flat (piecewise constant) patches). Why? It actually looks as if the image was padded by repeated values before upsampling.

Purge big files (and their version history) from a git repository

Wednesday, December 23rd, 2015
  1. fork the repo (e.g. using github web interface) and never touch the original again until confident that everything below worked
  2. clone fork
  3. cd fork
  4. git rm all big files
  5. git commit -m “removed big files”
  6. bfg –strip-blobs-bigger-than 20K .
  7. git reflog expire –expire=now –all && git gc –prune=now –aggressive
  8. git push origin –force master

Verify (e.g. on github website) that both repositories look as expected.