3

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]]}]]
Jenny
  • 559
  • 2
  • 9
  • 4
    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. – MarcoB Jan 31 '16 at 04:47
  • 1
    Use ( and ) to keep semicolon from ending your function definition like this: find[img_]:=(stmt1;stmt2;stmt3); – Bill Jan 31 '16 at 04: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 http://postimg.org/image/vmvrswlb3/ – Jenny Jan 31 '16 at 05:05
  • Probably worth your reading: (25507) – Mr.Wizard Jan 31 '16 at 08:04

1 Answers1

4

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257