在图像上应用Manipulate

时间:2017-12-24 04:56:04

标签: wolfram-mathematica

我尝试创建一个操作图像的函数,我可以在其中调整一些值color1,color2,val1,val2和num,并查看对图像的效果。下面是我处理具有固定值color1,color2,val1,val2和num的图像的代码。

我该怎么做?

val1 = 0.4;
val2 = 0.4
num = 2000
color1 = Red
color2 = Black
imageno = 1;
img = images[[imageno]];
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]

0 个答案:

没有答案