How can I create a surface with points distributed randomly ?

6 次查看(过去 30 天)
Hi
How can I create a surface with points distributed randomly like the attached file.
Best regards

采纳的回答

Walter Roberson
Walter Roberson 2019-4-6
N = 25;
x = rand(1,N) * 150; %wider than it is tall
y = rand(1,N) * 50;
pointsize = 20;
scatter(x, y, pointsize, 'filled')

更多回答(1 个)

Image Analyst
Image Analyst 2019-4-6
Try scatteredInterpolant()
  2 个评论
Image Analyst
Image Analyst 2019-4-10
编辑:Image Analyst 2019-4-10
Try this demo:
% Demo to show how scatteredInterpolant works to create a complete image out of arbitrarily placed sample points.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
numTrainingPoints = 50; % Number of points we'll have to try to estimate our image everywhere.
imageWidth = 300;
% Create sample surface
z = peaks(imageWidth);
[rows, columns] = size(z);
% Plot it as a flat image.
subplot(2, 2, 1);
imshow(z, []);
title('Original Image with Training Points in Red', 'FontSize', fontSize, 'Interpreter', 'None');
% Show it as a perspective 3-D-ish image.
subplot(2, 2, 3);
surf(z, 'EdgeColor', 'none');
title('Original Surface', 'FontSize', fontSize, 'Interpreter', 'None');
% Create sample coordinates
xi = imageWidth * rand(numTrainingPoints, 1);
yi = imageWidth * rand(numTrainingPoints, 1);
% Plot these over the image
subplot(2, 2, 1);
hold on;
plot(xi, yi, 'r.', 'MarkerSize', 15);
% Get z values. For this demo, let's get them from the peaks image.
% Then we'll try to recreate the peaks shape from the few points in x and y.
for k = 1 : length(xi)
zi(k) = z(ceil(yi(k)), ceil(xi(k)));
end
zi = zi'; % Make zi a column vector like scatteredInterpolant requires.
%================================ MAIN PART RIGHT HERE ==============================================
% Make the scattered interpolant.
F = scatteredInterpolant(xi, yi, zi)
% Get a grid of points at every pixel location in the RGB image.
[xGrid, yGrid] = meshgrid(1:columns, 1:rows);
xq = xGrid(:);
yq = yGrid(:);
% Evaluate the interpolant at query locations (xq,yq).
vq = F(xq, yq);
fittedImage = reshape(vq, rows, columns);
%================================ END OF MAIN PART ==============================================
% Plot it as a flat image.
subplot(2, 2, 2);
imshow(fittedImage, []);
title('Interpolated Image with Training Points in Red', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Plot the training points over the image.
hold on;
plot(xi, yi, 'r.', 'MarkerSize', 15);
% Show it as a perspective 3-D-ish image.
subplot(2, 2, 4);
surf(fittedImage, 'EdgeColor', 'none');
title('Interpolated Surface', 'FontSize', fontSize, 'Interpreter', 'None');
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
00_Screenshot.png

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by