I tried to create a Manipulate expression containing an image where I can adjust some values, color1, color2, val1, val2 and num to see the effect changing them have on the image.

My code for processing the image with fixed values for color1, color2, val1, val2 and num is shown below. How can I modify it to be interactive? color1, color2 can be chosen in colour spaces: Red,Green,Blue,Black,White etc val1,val2 in sliders with value from 0.1-1, step 0.1 num in slider: 100-5000 stepsize 100

val1 = 0.4;
val2 = 0.4
num = 2000
color1 = Red
color2 = Black

img = an image
   RemoveBackground[img, {"Foreground", {color1, val1}}], num]];
im = RemoveBackground[img, {"Foreground", {color2, val2}}];
ima = EdgeDetect[im];

cen = ComponentMeasurements[
   ima, {"Centroid"}, #Holes == 1 && 
     10 < #Area && #AdjacentBorderCount == 0 &];

b = Flatten[cen /. Rule -> List, 2]; (* remove arrow*)

(*sort out even and odd element, even elements contain coordinate for \
{x, y} = Partition[b, 2, 2, 1, {}]~Flatten~{2}; 
(*y : hole centroid location*)
dm = DelaunayMesh[y];

v = MeshPrimitives[dm, 0];
t = MeshPrimitives[dm, 2];

vedg = Length[Position[Level[t, {2}], #]] & /@ Level[v, {2}];
kN = Max[vedg];
mnloc = Flatten[Position[vedg, kN]];
mntri = Flatten[
   Position[ContainsAny[#, Level[v[[mnloc]], {2}]] & /@ Level[t, {2}],

nc = t[[mntri]];
knpic = Graphics[{Red, {PointSize[0.01], Point[y]}, Green, 
    MeshPrimitives[dm, 1], {Opacity[0.5], FaceForm[Red], 
     EdgeForm[{Thick, Red}], nc, FaceForm[Yellow]}}];
Show[img, knpic, ImageSize -> 500]

enter image description here

  • $\begingroup$ How do you want to Manipulate your colours? With named colours, like Red as you're doing, or with sliders (in which case you'll probably want to specify a colour space). Would val1 and val2 would be controlled by sliders, between 0 and 1? Also, you might want to include a sample image. $\endgroup$ – aardvark2012 Dec 24 '17 at 7:06
  • $\begingroup$ val1 and val2 are controlled by sliders from 0.1 to 1 with step 0.1. Color would be Red,Green,Black Blue...etc in color space. num is from 100 to 5000, stepsize 100. The problem is I cant zip all these code into a function with variable color1,2, val1,2 and num and then apply manipulate to that function $\endgroup$ – Dat Pham Hoang Dec 24 '17 at 20:37
  • $\begingroup$ I believe you need to provide img[[imageno]] in order for members to help with your question. $\endgroup$ – Jack LaVigne Dec 24 '17 at 21:07
  • $\begingroup$ it's just an image in my list of images. We can use any image $\endgroup$ – Dat Pham Hoang Dec 24 '17 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.