"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "macros/edge.sci" between
sip-0.5.6.tar.gz and sip-0.12.1.tar.gz

About: SIP (Scilab Image Processing) toolbox to do imaging tasks such as filtering, blurring, edge detection, thresholding, histogram manipulation, segmentation, mathematical morphology, color image processing, etc.

edge.sci  (sip-0.5.6):edge.sci  (sip-0.12.1)
function [border, thresh]=edge(Img, method, thresh, direction, sigma) function [border, thresh]=edge(Img, method, thresh, dir_or_sig, sig)
// //
// AUTHOR // AUTHOR
// Ricardo Fabbri <rfabbri@(not this part) gmail d0t com> // Ricardo Fabbri <rfabbri@(not this part) gmail d0t com>
// Cybernetic Vision Research Group // Cybernetic Vision Research Group
// Luciano da Fontoura Costa, supervisor. // Luciano da Fontoura Costa, supervisor.
// http://siptoolbox.sf.net // http://siptoolbox.sf.net
// //
// REFERENCE // REFERENCE
// "Algorithms for Image Processing and Computer Vision", // "Algorithms for Image Processing and Computer Vision",
// J.R. Parker, Wiley, chapter 1. // J.R. Parker, Wiley, chapter 1.
// //
// TODO // TODO
// - "edge" routine should have parameters "same" and "valid", just // - "edge" routine should have parameters "same" and "valid", just
// like imconv. // like imconv.
// //
// //
// $Revision: 1.2 $ $Date: 2009-03-29 21:34:48 $ // $Revision: 1.2 $ $Date: 2009-03-29 21:34:48 $
if argn(2)==0 then if argn(2)==0 then
error('Invalid number of arguments.') error('Invalid number of arguments.')
else end
if ~exists('method','local') then
method='sobel' //check image channel
end if size( size(Img),2) <> 2 then
if ~exists('thresh','local') then error('The input image should be a single channel image.');
thresh=0.5; end
end
if ~exists('direction','local') then if ~exists('method','local') then
direction='both' method='sobel'
end end
if ~exists('thresh','local') then
thresh=0.2;
end
direction='both'; //default value
sigma = []; //default value
if exists('dir_or_sig', 'local') then
if( typeof(dir_or_sig) == 'string') then
direction = dir_or_sig;
elseif (typeof(dir_or_sig) == 'constant') then
sigma = dir_or_sig;
end
end
if exists('sig', 'local') then
sigma = sig;
end end
select method select method
case 'sobel' then case 'sobel' then
mask = mkfilter('sobel') mask = mkfilter('sobel')
case 'prewitt' then case 'prewitt' then
mask = mkfilter('prewitt') mask = mkfilter('prewitt')
case 'canny' then
//set default thresh value
//negative value is invalid here
if thresh < 0 then
thresh = 0.5;
end
if(length(thresh)==1) then
low_th=thresh*0.4;
high_th=thresh;
else
low_th=thresh(1);
high_th=thresh(2);
end
if isempty(sigma) then
sigma=3;
end
if and(sigma <> [3,5,7]) then
error('sigma for canny means kernel size (width), and must be 3, 5 or 7.');
end
if (typeof(Img(1)) == 'constant')
Img = Img*255;
end
border = canny_c(Img, low_th*1024, high_th*1024, sigma);
border = im2bw(double(border), 0.5);
//END of CANNY
return;
case 'fftderiv' // fourier gradient case 'fftderiv' // fourier gradient
if ~exists('sigma','local') then if ~exists('sigma','local') | isempty(sigma) then
sigma=1 sigma=1
end end
[r,c] = size(Img)
fu = [0:c-1]*(1/c) [r,c] = size(Img)
fv = [0:r-1]*(1/r) fu = [0:c-1]*(1/c)
fu(int(c/2):c) = fu(int(c/2):c) - 1; fv = [0:r-1]*(1/r)
fv(int(r/2):r) = fv(int(r/2):r) - 1; fu(int(c/2):c) = fu(int(c/2):c) - 1;
fv(int(r/2):r) = fv(int(r/2):r) - 1;
if sigma == 0
gf = ones(r,c) if sigma == 0
else gf = ones(r,c)
gf = ones(r,1) * exp(-(sigma*%pi*fu)^2) else
gv = exp(-(sigma*%pi*fv')^2) * ones(1,c) gf = ones(r,1) * exp(-(sigma*%pi*fu)^2)
gf = gf .* gv gv = exp(-(sigma*%pi*fv')^2) * ones(1,c)
end gf = gf .* gv
end
select direction
case 'horizontal' select direction
fvp = %i*2*%pi*fv' * ones(1,c) case 'horizontal'
Dyf = fft(Img,-1) .* gf .* fvp fvp = %i*2*%pi*fv' * ones(1,c)
border = abs(fft(Dyf,1)) Dyf = fft(Img,-1) .* gf .* fvp
case 'vertical' border = abs(fft(Dyf,1))
fup = ones(r,1) * %i*2*%pi*fu case 'vertical'
Dxf = fft(Img,-1) .* gf .* fup fup = ones(r,1) * %i*2*%pi*fu
border = abs(fft(Dxf,1)) Dxf = fft(Img,-1) .* gf .* fup
case 'both' border = abs(fft(Dxf,1))
fup = ones(r,1) * %i*2*%pi*fu case 'both'
fvp = %i*2*%pi*fv' * ones(1,c) fup = ones(r,1) * %i*2*%pi*fu
Dxf = fft(Img,-1) .* gf .* fup fvp = %i*2*%pi*fv' * ones(1,c)
Dyf = fft(Img,-1) .* gf .* fvp Dxf = fft(Img,-1) .* gf .* fup
Dyf = fft(Img,-1) .* gf .* fvp
Dx = abs(fft(Dxf,1))
Dy = abs(fft(Dyf,1)) Dx = abs(fft(Dxf,1))
Dy = abs(fft(Dyf,1))
border = sqrt(Dx.^2 + Dy.^2)
else border = sqrt(Dx.^2 + Dy.^2)
error('Invalid direction.'); else
end error('Invalid direction.');
if thresh >=0 then end
border=im2bw(border,thresh,max(border)) if thresh >=0 then
end border=im2bw(border,thresh,max(border))
// END end
return // END
return
else else
error('Invalid edge detection method.') error('Invalid edge detection method.')
end end
select direction select direction
case 'horizontal' case 'horizontal'
mx=imconv(Img,mask); mx=imconv(Img,mask);
border=abs(mx) border=abs(mx)
case 'vertical' case 'vertical'
my=imconv(Img,-mask'); my=imconv(Img,-mask');
border=abs(my) border=abs(my)
case 'both' case 'both'
mx=imconv(Img,mask); mx=imconv(Img,mask);
my=imconv(Img,-mask'); my=imconv(Img,-mask');
border=sqrt(mx.*mx + my.*my); border=sqrt(mx.*mx + my.*my);
else else
error('Invalid direction.'); error('Invalid direction.');
end end
if thresh >=0 then if thresh >=0 then
border=im2bw(border,thresh,max(border)) border=im2bw(border,thresh,max(border))
end end
endfunction endfunction
// //
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// SIP - Scilab Image Processing toolbox // SIP - Scilab Image Processing toolbox
// Copyright (C) 2002-2009 Ricardo Fabbri // Copyright (C) 2002-2009 Ricardo Fabbri
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
 End of changes. 11 change blocks. 
68 lines changed or deleted 117 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS