Triangle Circle Dataset Creation

조회 수: 5 (최근 30일)
marsmar
marsmar 2022년 11월 15일
편집: DGM 2022년 11월 26일
I need to generate a triangle in matlab in the scope of 500x500 pixels. I need to generate a certain amount of images so its a dataset. The triangles either need to be at a certain angle and be either pink or purple. I have no idea what commands to use.
  댓글 수: 2
DGM
DGM 2022년 11월 15일
What are the constraints?
  • Do they need to be a certain configuration? Irregular? Regular?
  • How many triangles per image?
  • Do they need to be a certain size?
  • Do they need to be in a certain position?
  • Can they intersect image boundaries?
  • What's the background?
  • Are the triangles supposed to be a particular pink/purple, or can it be any random color in that range?
  • Do the triangles need to be binarized, or should they be antialiased?
marsmar
marsmar 2022년 11월 25일
They can be irregular or regular! I just need one triangle per image and they just need to be within the 500x500 pixels. They can be in any position and it could vary. The background by default is white. They can be in any random color range.

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

채택된 답변

DGM
DGM 2022년 11월 16일
Until clarification, here's a crude example.
% some parameters, maybe?
szo = [500 500]; % [y x]
fgcolor = [0.7 0.3 1];
bgcolor = [0 0 0.2];
% does any of this need to be fixed? random?
% this will use a fixed radius
% but angles and center are contrained random
r = 100;
center = (szo-2*r-1).*rand(1,2)+1+r; % [y x]
angles = 0:120:240;
angles = angles + 10*rand() + 10*randn(size(angles));
angles = [angles angles(1)];
x = r*cosd(angles) + center(2);
y = r*sind(angles) + center(1);
% create a mask
mask = poly2mask(x,y,szo(1),szo(2));
% create the ouput image (no antialiasing)
outpict = repmat(permute(bgcolor,[1 3 2]),szo);
outpict = mask.*permute(fgcolor,[1 3 2]) + (1-mask).*outpict;
outpict = im2uint8(outpict);
imshow(outpict)
  댓글 수: 7
marsmar
marsmar 2022년 11월 25일
I have an error with the "randrange" function. Is it a function specific to a certain toolbox? I'm trying to recreate a square and had just edited the "nvert" number to 4.
DGM
DGM 2022년 11월 26일
편집: DGM 2022년 11월 26일
I attached randrange(). It's just a convenience tool that I used and didn't bother removing. It's basically just one line. You could also simply just replace the one where it's used with
r = rlimits(1) + rand()*range(rlimits);

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

추가 답변 (1개)

David Hill
David Hill 2022년 11월 15일
Look at polyshape

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by