Generate binary image of geometric shapes?
15 views (last 30 days)
Image Analyst on 6 May 2015
Edited: Image Analyst on 6 May 2015
I thought I helped you in your prior posting of this question. Here is the code from there:
xCenter = 12;
yCenter = 10;
% Modification to the FAQ is the next two lines.
numSides = 6; % <=== CHANGE THIS NUMBER
theta = linspace(0, 2*pi, numSides + 1);
% Rotate the shape by subtracting an offset.
theta = theta - pi/3;
radius = 5;
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;
Feel free to adapt as necessary to change center, radius, rotation angle, etc.
You can make a binary image of it with poly2mask()
binaryImage = poly2mask(x, y, rows, columns);
You have to specify the number of rows and columns you want in the image.
More Answers (1)
Alka Nair on 6 May 2015
Hi, For generating geometric shapes in binary images use STREL to create the structuring element, for example, suppose you want to generate a square. The steps are as follows: >>img = zeros(100,100); >>imgLogical = logical(img); >>img(50,50)=1; % fixing the initial seed point >>se1 = strel('square',12); >>im2 = imdilate(f,se1);
Please refer to the documentation for STREL at the following location: http://www.mathworks.com/help/images/ref/strel.html