Created
January 21, 2013 12:26
-
-
Save jaderberg/4585711 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Max Jaderberg 10/11/12 | |
% Computes the Stroke Width Transform (SWT) of an image using CCV. | |
% Need to specify bright to dark or dark to bright. Most applications do | |
% both. direction should be 0 (dark to bright) or 1 (bright to dark). | |
function im_swt = swt(im, direction, size, low_thresh, high_thresh, visualize) | |
% default direction is dark to bright (direction=0) | |
options = [ | |
direction; | |
size; | |
low_thresh; | |
high_thresh; | |
visualize; | |
]; | |
opt_flags = 'rslhv'; | |
opt_hasarg = [0 1 1 1 0]; | |
opts_args = ' '; | |
for i=1:length(options) | |
if options(i) | |
if opt_hasarg(i) | |
opts_args = [opts_args '-' opt_flags(i) ' ' num2str(options(i)) ' ']; | |
else | |
opts_args = [opts_args '-' opt_flags(i) ' ']; | |
end | |
end | |
end | |
n = 5; | |
LetterStore = char(97:122); | |
rand_string = LetterStore(ceil(length(LetterStore).*rand(1,n))); | |
[path name ext] = fileparts(mfilename('fullpath')); | |
temp_file = fullfile(path,[rand_string 'swt.jpg']); | |
imwrite(im, temp_file); | |
% call swt | |
system(['swt ' opts_args temp_file ' ' temp_file]); | |
im_swt = imread(temp_file); | |
system(['rm -f ' temp_file]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment