How can I create a surface with points distributed randomly ?

조회 수: 11 (최근 30일)
Mallouli Marwa
Mallouli Marwa 2019년 4월 6일
편집: Image Analyst 2019년 4월 10일
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
Mallouli Marwa
Mallouli Marwa 2019년 4월 6일
How can I simulate it ?
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

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by