# Define a function with multiple lines mathematica [closed]

How is this done?

find[img_] :=
centerOne =
ImageTransformation[src, img, {200, 200}, DataRange -> Full,
PlotRange -> {{0, 1}, {0, 1}}], bin =
Dilation[EdgeDetect[centerOne], 3],
components =
ComponentMeasurements[
bin, {"Centroid", "Area", "FilledCircularity",
"EquivalentDiskRadius"}, #2 > 100 &];, Show[centerOne,
Graphics[{Thick {If[#[[3]] > 0.2, Red, Blue],
Circle[#[[1]], #[[4]]]} & /@ components[[All, 2]]}]]

• Wrap all statements in a Module and separate them with a semicolon. The output of the last statement will be the return value of your function. Take a look at other answers from this site; I'm sure you'll find examples of this style. Jan 31, 2016 at 4:47
• Use ( and ) to keep semicolon from ending your function definition like this: find[img_]:=(stmt1;stmt2;stmt3);
– Bill
Jan 31, 2016 at 4:56
• When i run the exact code line by line I get a red circle around the O in the final image, however when I run it as a function I get this postimg.org/image/vmvrswlb3 Jan 31, 2016 at 5:05

Your code can be transformed in a function definition as follows:

find[img_] :=
Module[{centerOne, bin, components},
centerOne =
ImageTransformation[src, img, {200, 200},
DataRange -> Full, PlotRange -> {{0, 1}, {0, 1}}];
bin = Dilation[EdgeDetect[centerOne], 3];
components =
ComponentMeasurements[
bin,
#2 > 100 &];
Show[
centerOne,
Graphics[{
Thick,
{If[#[[3]] > 0.2, Red, Blue], Circle[#[[1]], #[[4]]]} & /@
components[[All, 2]]}]]]


But this function will not produce useful results because

ImageTransformation[src, img, {200, 200},
DataRange -> Full, PlotRange -> {{0, 1}, {0, 1}}];


is not a valid call of ImageTransformation. You call should have the form

ImageTransformation[img, f, {200, 200},
DataRange -> Full, PlotRange -> {{0, 1}, {0, 1}}];


where