Skip to content

Instantly share code, notes, and snippets.

function radius = imradius(sz)
% imradius
% radius = imradius(sz)
%
% return radius in pixcels in an images sz
radius = hypot(((1:sz(1)) - sz(1)/2 - 0.5)', ((1:sz(2)) - sz(2)/2 - 0.5));
@gkhtnk
gkhtnk / centeriseCAxis.matlab
Created March 16, 2017 09:03
Centerise the caxis used in colormap.
caxis([-max(abs(caxis)), max(abs(caxis))]);
@gkhtnk
gkhtnk / MovieData2frame.matlab
Last active March 5, 2017 13:45
Convert sequential MovieData(m x n x c x t) to frame struct. How to adapt im2frame function for 4-D Data.
% MovieData should be arranged 4D [col, row, rgb, time]
% convert to frame (for movie function or writeVideo function in VideoWriter class)
%% Test RGB Data (with for loop)
NofFrame = 300;
MovieData = rand(64, 64, 3, NofFrame);
for fi = 1:NofFrame
frame(fi) = im2frame(MovieData(:, :, :, fi));
end
movie(frame, 1, 30);
@gkhtnk
gkhtnk / slack_incoming.matlab
Last active July 13, 2018 04:04
Send message to slck from Matlab using Slack incoming API
function response = slack_incoming(url, varargin)
%% response = slack_incoming(url, payload)
% url : [char] Webhook URL (you have to get Webhook URL from Slack)
% payload : [char, struct] payload must be JSON style string or struct
% # payload is a case when varagin is a single argument
% varargin : [char/char] optional mode for define payload as key/value pair
%
% response : 'ok' POST of payload was succeeded.
% otherwise failed to POST
%
function Hash = getGitHash(varargin)
if nargin == 0 || strcmp(varargin{1}, 'HEAD')
[~, ans] = system('git rev-parse HEAD');
elseif nargin == 1 && isstr(varargin{1})
[~, ans] = system(sprintf('git rev-parse %s', varargin{1});
end
function varargout = Cellfun(varargin)
%% Cellfun <- cellfun
% Avoid to type 'UniformOutput', false
if nargin
if nargout
varargout = cellfun(varargin{:}, 'UniformOutput', false);
else
cellfun(varargin{:}, 'UniformOutput', false);
end
end
@gkhtnk
gkhtnk / getSeqFile.sh
Created October 21, 2016 18:07
Get pdf file sequentially
# Replace <http://example.com/lecture%d.pdf> to specified filename
for i in {1..2}; do wget $(printf <http://example.com/lecture%d.pdf> $i); done;
checker = @(X, Y, w, h, dx, dy) (mod(ceil((X-dx)/w), 2) == mod(ceil((Y-dy)/h), 2));
XYrange = @(X, Y, Xmin, Xmax, Ymin, Ymax) (Xmin <= X & X <= Xmax & Ymin <= Y & Y <= Ymax);
[X, Y] = meshgrid(1:1920, 1:1080);
[THETA,RHO] = cart2pol(X-mean(X(:)), Y-mean(Y(:)));
THETA = -THETA;
Img = double(checker((180*THETA/pi), RHO, 15, 50, 0, 0) & XYrange(THETA, RHO, -inf, inf, 200, 400)) + ...
double(not(XYrange(THETA, RHO, -inf, inf, 200, 400))).*0.5;
checker = @(X, Y, w, h, dx, dy) uint8((mod(ceil((X-dx)/w), 2) == mod(ceil((Y-dy)/h), 2)).*255);
[X, Y] = meshgrid(1:1920, 1:1080);
Img = checker(X, Y, 120, 120, 0, 0)
imagesc(Img);
imwrite(Img, filename);