3
$\begingroup$

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]]}]]
$\endgroup$
  • 3
    $\begingroup$ 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. $\endgroup$ – MarcoB Jan 31 '16 at 4:47
  • 1
    $\begingroup$ Use ( and ) to keep semicolon from ending your function definition like this: find[img_]:=(stmt1;stmt2;stmt3); $\endgroup$ – Bill Jan 31 '16 at 4:56
  • $\begingroup$ 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 $\endgroup$ – Jenny Jan 31 '16 at 5:05
  • $\begingroup$ Probably worth your reading: (25507) $\endgroup$ – Mr.Wizard Jan 31 '16 at 8:04
3
$\begingroup$

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, 
        {"Centroid", "Area", "FilledCircularity", "EquivalentDiskRadius"}, 
        #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

docs

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.