type BiSmooth.m
% smooth image A using a binomial filters of order p (should be even)
function [SI] = BiSmooth(A,p);
X = [1 2 1];
c = 4;
for i=2:2:p-2,
X = conv(X,[1 2 1]);
c = c*4;
end;
I1 = filter2(X/c,A);
I2 = filter2(X'/c,I1);
SI = uint8(I2);
ls *.ppm
??? Error using ==> ls at 38
ls: *.ppm: No such file or directory
ls *.png
??? Error using ==> ls at 38
ls: *.png: No such file or directory
I = imread('background.tif');
whos
Name Size Bytes Class Attributes
I 480x640x3 921600 uint8
Ig = rgb2gray(I);
whos
Name Size Bytes Class Attributes
I 480x640x3 921600 uint8
Ig 480x640 307200 uint8
figure, imshow(Ig);
Is = BiSmooth(Ig,4);
figure, imshow(Ig);
figure, imshow(Is);
figure, plot(Ig(240,:),'b');
hold;
Current plot held
plot(Is(240,:),'r');
Is2 = BiSmooth(Ig,8);
figure, imshow(Is2);
figure(4), plot(Is2(240,:),'g');
Is2 = BiSmooth(Ig,8);
X =
1 8 28 56 70 56 28 8 1
c =
256
Is2 = BiSmooth(Ig,16);
X =
Columns 1 through 13
1 16 120 560 1820 4368 8008 11440 12870 11440 8008 4368 1820
Columns 14 through 17
560 120 16 1
c =
65536
figure, imshow(Is2);
figure(4), plot(Is2(240,:),'c');
type Gradient.m
% Partial derivatives in X and Y directions
function [Gx,Gy] = Gradient(A, p);
X = [-1 0 1]/2; % filter
Y = [1 0 -1]'/2; % filter
Gx = filter2(X,A); % correlation
Gy = filter2(Y,A);
[M,N] = size(A);
Gx(1:p+1,:) = 0;
Gx(M-p-1:M,:) = 0;
Gx(:,1:p+1) = 0;
Gx(:,N-p-1:N) = 0;
Gy(1:p+1,:) = 0;
Gy(M-p-1:M,:) = 0;
Gy(:,1:p+1) = 0;
Gy(:,N-p-1:N) = 0;
type Gradient.m
% Partial derivatives in X and Y directions
function [Gx,Gy] = Gradient(A, p);
X = [-1 0 1]/2; % filter
Y = [1 0 -1]'/2; % filter
Gx = filter2(X,A); % correlation
Gy = filter2(Y,A);
[M,N] = size(A);
Gx(1:p+1,:) = 0;
Gx(M-p-1:M,:) = 0;
Gx(:,1:p+1) = 0;
Gx(:,N-p-1:N) = 0;
Gy(1:p+1,:) = 0;
Gy(M-p-1:M,:) = 0;
Gy(:,1:p+1) = 0;
Gy(:,N-p-1:N) = 0;
[Gx,Gy] = Gradient(Ig,2);
[Gx1,Gy1] = Gradient(Is,4);
[Gx2,Gy2] = Gradient(Is2,16);
help imagesc
IMAGESC Scale data and display as image.
IMAGESC(...) is the same as IMAGE(...) except the data is scaled
to use the full colormap.
IMAGESC(...,CLIM) where CLIM = [CLOW CHIGH] can specify the
scaling.
See also image, colorbar, imread, imwrite.
Reference page in Help browser
doc imagesc
figure, imagesc(Gx);
figure, imagesc(Gx1);
figure, imagesc(Gx2);
figure, plot(Gx(240,:)); hold;
Current plot held
plot(Gx1(240,:),'r);
??? plot(Gx1(240,:),'r);
|
Error: A MATLAB string constant is not terminated properly.
plot(Gx1(240,:),'r');
plot(Gx2(240,:),'c');
type FlowDisplay.m
function [] = FlowDisplay(NF,maxnf)
ind = find(~isnan(NF(:,5)) & (abs(NF(:,5))feather, quiver3, plot.
Reference page in Help browser
doc quiver
edit
DisplayGradients(Gx,Gy,5);
figure, DisplayGradients(Gx,Gy,5);
figure, DisplayGradients(Gx1,Gy1,5);
figure, DisplayGradients(Gx2,Gy2,5);
figure, DisplayGradients(Gx2,Gy2,1);
figure, DisplayGradients(Gx2,Gy2,2.5);
help quiver3
QUIVER3 3-D quiver plot.
QUIVER3(X,Y,Z,U,V,W) plots velocity vectors as arrows with components
(u,v,w) at the points (x,y,z). The matrices X,Y,Z,U,V,W must all be
the same size and contain the corresponding position and velocity
components. QUIVER3 automatically scales the arrows to fit.
QUIVER3(Z,U,V,W) plots velocity vectors at the equally spaced
surface points specified by the matrix Z.
QUIVER3(Z,U,V,W,S) or QUIVER3(X,Y,Z,U,V,W,S) automatically
scales the arrows to fit and then stretches them by S.
Use S=0 to plot the arrows without the automatic scaling.
QUIVER3(...,LINESPEC) uses the plot linestyle specified for
the velocity vectors. Any marker in LINESPEC is drawn at the base
instead of an arrow on the tip. Use a marker of '.' to specify
no marker at all. See PLOT for other possibilities.
QUIVER3(...,'filled') fills any markers specified.
QUIVER3(AX,...) plots into AX instead of GCA.
H = QUIVER3(...) returns a quiver object.
Example:
[x,y] = meshgrid(-2:.2:2,-1:.15:1);
z = x .* exp(-x.^2 - y.^2);
[u,v,w] = surfnorm(x,y,z);
quiver3(x,y,z,u,v,w); hold on, surf(x,y,z), hold off
See also quiver, plot, plot3, scatter.
Reference page in Help browser
doc quiver3
type NMS.m
% Non-maximum suppression for a gradient image;
% magnitudes under t are ignored
% returns a binary image where maximal gradient values are non-zero
function [m1] = NMS(Gx,Gy,t);
m = sqrt(Gx.^2+Gy.^2); % magnitude
I1 = find(m0 % for all points for which m>t do
if Gx(i,j)>0
dx = 1;
else
dx = -1;
end;
if Gy(i,j)>0
dy = 1;
else
dy = -1;
end;
if aGx(i,j)>aGy(i,j) % x is dominant direction
m01 = m(i,j+dx);
m11 = m(i-dy,j+dx);
m_01 = m(i,j-dx);
m_11 = m(i+dy,j-dx);
m1 = (aGx(i,j)-aGy(i,j))*m01 + aGy(i,j)*m11;
m2 = (aGx(i,j)-aGy(i,j))*m_01 + aGy(i,j)*m_11;
mag = m(i,j)*aGx(i,j);
if (mag>m2) & (mag>=m1)
Z(i,j) = 1;
end
else % y is dominant direction
m01 = m(i-dy,j);
m11 = m(i-dy,j+dx);
m_01 = m(i+dy,j);
m_11 = m(i+dy,j-dx);
m1 = (aGy(i,j)-aGx(i,j))*m01 + aGx(i,j)*m11;
m2 = (aGy(i,j)-aGx(i,j))*m_01 + aGx(i,j)*m_11;
mag = m(i,j)*aGy(i,j);
if (mag>m2) & (mag>=m1)
Z(i,j) = 1;
end
end
end % if (m,j)>0
end % for
end % for
I1 = find(Z==0); % only keep points where Z=1
m(I1)=0;
m1 = uint8(m);
figure, DisplayGradients(Gx2,Gy2,2.5);