mercredi 3 février 2021

How to create a random shape (blob) in Matlab

I am trying to create random shapes that look like blobs, such as the one on this picture: Blob shape image.

I tried to draw and to overlap circles and/or ellipses to create a similar shape and use the poly2mask function to extract a binary image (see an example below). But I don't manage to get a satisfying result. Any idea about how to obtain such a shape would be appreciated!

function bw = angular_blob(centerX, centerY, im_height,im_width)
% angular_blob: Creates a mask for an angular blob shape 
%  Parameters of the function:
%      im_height and im_width: dimensions of the mask image
%      centerX, centerY: determines the centre of the blob patch

k    = round(rand(1,50)*10)+25;   % polar coordinate rho
Th   = linspace(0,2*pi,50);       % polar coordinate theta
k    = [k  k(1)];
Th   = [Th  Th(1)];
[x, y] = pol2cart(Th, k);

Xint = round(x) + centerX;
Yint = round(y) + centerY;
bw   = poly2mask(Xint,Yint,im_height,im_width);




Aucun commentaire:

Enregistrer un commentaire