# CLOUD Define a Region Using Boundary Points Read From a File

cloud, a FreeFem++ code which starts with a black and white drawing of a cloud, uses MATLAB to extract the boundary, reads the boundary into FreeFem++ and solves a Poisson problem over the region.

In this particular example, the computation begins with a PNG image of a cloud, which consists of a white region surrounded by a black region, and nothing else. (This simplicity is important, in order for MATLAB to detect just one continuous boundary. If this is not the case, then you can still do this, but it takes some human intervention.)

A MATLAB function from the image toolbox is able to report a list of pixel locations corresponding to the black/white border. These pairs of coordinates can be written to a file, preceded by a single line listing the number of such coordinates. (In fact, we have to thin the data, and we have to reverse its order, and we have to make sure that the first point is repeated at the end so that FreeFem++ can tell that the border closes up.)

FreeFem++ can read the file, and can be instructed to regard the data as defining the border of a region. To show that this is true, we go ahead and mesh the region and solve some hokey PDE on it.

### Reference:

• Frederic Hecht,
New development in FreeFem++,
Journal of Numerical Mathematics,
Volume 20, Number 3-4, 2012, pages 251-265.

### Source Code:

• cloud.png, a very simple drawing of a cloud, white surrounded by black;
• cloud.m, a MATLAB script which processes the cloud image and writes the data file.
• image_boundary.m, a MATLAB script called by cloud.m, which takes care of talking to the image toolbox.
• cloud_points.txt, the list of pixels forming the border. Because of the difference in conventions between (X,Y) Cartesian coordinates and the (I,J) numbering of pixels, the region will essentially be rotated by 90 or -90 degrees, who cares which one it is?

Last revised on 24 May 2020.