Imagine you have an irregular image like this:
How would you solve a differential equation or compute an integral over a region of this shape?
First, let’s get the boundary:
i = Import["http://wolfr.am/ZS7ERg"];
edge = EdgeDetect[ColorNegate[i]]
It is now easy to extract points with Position but how to order them inside Polygon correctly along the boundary? Using FindShortestTour! - a trick I learned from this excellent post: Find polygons corresponding to image borders
reg = MeshRegion[#, Polygon[Last[FindShortestTour[#]]]] &@ Position[ImageData[edge], 1]
Now we are ready to have fun:
Plot3D[Cos[.0002 ((x - 215)^2 + (y - 215)^2)]^2, {x, y} \[Element] reg,
Mesh -> None, Filling -> -3, FillingStyle -> Red, PlotRange -> All, BoxRatios -> {1, 1, 1/3}]
uif = NDSolveValue[{\!\(\*SubsuperscriptBox[\(\[Del]\), \({x, y}\), \(2\)]\(u[x, y]\)\) == 0,
DirichletCondition[u[x, y] == 1/2 + Sin[.0001 x y] , True]}, u, {x, y} \[Element] reg];
ContourPlot[uif[x, y], {x, y} \[Element] reg, PlotPoints -> 50,
ContourStyle -> Opacity[.2], Contours -> 50, ColorFunction -> "Rainbow"]











