function heightthreshold(n) % Simple script to generate random numbers and a threshold % Script source: http://www.poirrier.be/~jean-etienne/presentations/rft/ % How to run it? Just type "heightthreshold(n)" % with n = number of pixels on 1 side % First part of the graph: random values s = randn(n); s = exp(s); % Compute replacement of random values by the mean within each square % It's not for smoothing things but big points are better seen dim = 2; % square dimension --> can be modified for any other dimension nsquare = n / dim; % number of squares in one dimension of image sum = 0; % sum of values for each square nv = 0; % number of values collected in each square for i = 1:nsquare for j = 1:nsquare % traverse each square to collect random data for k = ((i - 1) * dim + 1):((i - 1) * dim + dim) for l = ((j - 1) * dim + 1):((j - 1) * dim + dim) % get data sum = sum + s(k, l); nv = nv + 1; end end mean = sum / nv; % traverse each square to put means data for k = ((i - 1) * dim + 1):((i - 1) * dim + dim) for l = ((j - 1) * dim + 1):((j - 1) * dim + dim) % put the mean s(k, l) = mean; end end % reset values sum = 0; nv = 0; end end % Display graph surf(s); hold on; % Beautification of graph title('Ensemble de valeurs aleatoires'); xlabel('Position du pixel en X'); ylabel('Position du pixel en Y'); zlabel('Valeur du pixel exprimee en Z'); colormap(cool); pause; % Second part of the graph: threshold at pct% of maximum value pct = 70; filter = max(max(s)) * (pct/100); for i = 1:n for j = 1:n t(i,j) = filter; end end surf(t); % Beautification of graph title('Ensemble de valeurs aleatoires avec filtre'); hold off;