How to generate the modeling of particle environment

조회 수: 1 (최근 30일)
abd elkarim
abd elkarim 2017년 6월 3일
답변: Image Analyst 2017년 6월 4일
How to generate the modeling of particle environment in a room contains a circular obstacle. just I'll know how to trace the edges, size of the room and the obstacle by points (and the plot() command) on Matlab.

채택된 답변

Image Analyst
Image Analyst 2017년 6월 4일
Try this. Adapt as needed:
% Initialization steps.
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;
% Make a circular image mask.
% Adapted from FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 240;
[columnsInImage, rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 320;
centerY = 120;
radius = 70;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
subplot(2, 2, 2);
image(circlePixels) ;
axis image;
title('Binary image of a circle', 'FontSize', fontSize);
colormap([0 0 0; 1 1 1]);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% 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')
numPoints = 500;
% Create pattern of random points with y = 1 to 11 and x = 0 to 32
x = floor(imageSizeX * rand(1, numPoints)) + 1;
y = floor(imageSizeY * 0.9 * rand(1, numPoints) + 0.1 * imageSizeY) + 1;
% Create an image of gray
grayLevel = 64; % Whatever you want between 0 and 255.
grayImage = grayLevel * ones(imageSizeY, imageSizeX, 'uint8');
for k = 1 : numPoints
grayImage(y(k), x(k)) = 255;
end
subplot(2, 2, 1);
imshow(grayImage);
axis on;
title('Original Points', 'FontSize', fontSize);
% Now mask the image
grayImage(circlePixels) = grayLevel;
subplot(2, 2, 3);
imshow(grayImage);
axis on;
title('Masked Points', 'FontSize', fontSize);
It creates an array of random points. Then it creates a circle mask. Then it erases the points that happened to fall within the circle mask.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by