Skip to content

Instantly share code, notes, and snippets.

@jaderberg
Created January 21, 2013 12:26
Show Gist options
  • Select an option

  • Save jaderberg/4585711 to your computer and use it in GitHub Desktop.

Select an option

Save jaderberg/4585711 to your computer and use it in GitHub Desktop.

Revisions

  1. jaderberg created this gist Jan 21, 2013.
    47 changes: 47 additions & 0 deletions swt.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    % 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]);