# Manipulating an Image to see the effect of changing certain properties

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
DeleteSmallComponents[
MorphologicalComponents[
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 \
hole*)
{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}],
True]];

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]


• 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. – aardvark2012 Dec 24 '17 at 7:06
• 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 – Dat Pham Hoang Dec 24 '17 at 20:37
• I believe you need to provide img[[imageno]] in order for members to help with your question. – Jack LaVigne Dec 24 '17 at 21:07
• it's just an image in my list of images. We can use any image – Dat Pham Hoang Dec 24 '17 at 22:28