希臘藝術家 P. Vrellis 用編織畫人像畫的效果是怎麼實現的?
參見:新的繪畫材料出現了?讓人咋舌的設計方法
有一個網站,可以一鍵實現這種效果。
效果圖
先給出給出網站
Create Line Art
我們上傳一張照片,一張處理過的孔雀。
點draw就可以了,選中color,調下參數,你還可以做出彩色的效果。
答題結束!收藏是贊的三倍還多,不要只收藏不點贊啊!
========================
順便有一個困擾我的問題,技術是有了,我們能用這種效果做什麼呢?
雖然是手工編織的,但是有程序幫助。
The "weave" sequence is done completely by hand, however each step is mapped out by a computer through a specially designed algorithm that converts a digital photograph into a peg-by-peg knitting pattern.
來源
Code Your Way to Woven Photographs
另外已經有人看不慣這個手工重複並拿來賣錢(一幅畫快2000美金),已經在做自動版的了。
來源
https://hackaday.io/project/13047-automate-the-art
感覺這個可以拿來做遺傳演算法的練習題……
artist 肯定也是先算出來過然後再製作的
直接copy我公眾號【壞印表機】上推送的答案。用processing寫程序,就可以實現,順便導出連線信息,導入C4D里用python生成樣條,加上毛髮渲染,可以做3D的東西。
繞線作畫—在線播放—優酷網,視頻高清在線觀看視頻
--------------------------------------------------
根據http://linify.me上提供的思路,我用processing還原一下這個程序。思路如下:
簡單來說,就是一個貪心隨機演算法。
①、隨機尋找一個亮度值低於閾值(80)的像素點。
②、找出所有由200個點中任意兩個點連成的,並且離該像素點最近的線。
③、在這些線裡面,計算每條線上經過的像素的平均亮度值,畫出最低亮度值的那條線。
④、被畫出來的那條線經過的所有像素,將亮度值設為最大(255),即不參與下次循環。我在程序里是把亮度值加一個fadeStep(40),而沒有直接粗暴設為255。
⑤、重複以上過程,直到畫出lineNum(2500)條線。
Processing
用Processing碼了150行,效果和http://linify.me網站上差不多,拿瑪麗蓮夢露和愛因斯坦的照片做個測試。
在程序里裡面,我設置圓周一共有200個掛鉤,這樣的話再把連線信息導出txt文件出來。然後買一塊圓盤和1.km的線,花一天時間,就可以做一個裝飾品了。
C4D
剛好想看一下學一下C4D python的模塊,於是把processing導出的txt裡面的連線信息,導入C4D的python generator裡面,作為一個數組存在,用於生成C4D裡面的樣條,並添加生長動畫效果。
這裡有一個問題,如果把代碼寫在python tag裡面, 然後把tag賦予一個樣條對象,這樣的話樣條沒辦法每次都更新狀態。如果把代碼寫在python generator裡面,有動畫,但是沒有辦法把毛髮材質加在上面,這能用掃描或者素描渲染,前者太慢,後者太粗糙。
因此,下面只渲染靜幀。
誰想試下就試下吧,給條路徑。圓上200個點,從某個點開始,順著依次命名1,2,3....199,200。
連線:{{115, 195, 84, 184, 49, 185, 32, 178, 13, 114, 199, 47, 156, 199,
155, 194, 115, 164, 39, 174, 120, 173, 194, 122, 174, 81, 197, 22,
84, 121, 144, 117, 142, 112, 189, 50, 192, 17, 118, 143, 97, 138,
91, 136, 33, 164, 111, 141, 71, 108, 160, 32, 62, 126, 178, 45, 153,
198, 152, 193, 19, 105, 154, 199, 176, 197, 23, 104, 139, 98, 138,
113, 192, 54, 189, 35, 94, 141, 72, 145, 123, 86, 198, 87, 124, 145,
73, 108, 159, 75, 157, 200, 46, 188, 11, 101, 148, 100, 139, 93,
140, 107, 154, 197, 152, 195, 151, 194, 153, 197, 86, 119, 142, 109,
196, 78, 111, 140, 92, 135, 33, 64, 130, 29, 152, 194, 41, 177,
200, 24, 117, 143, 72, 146, 122, 195, 172, 198, 177, 196, 46, 179,
43, 180, 12, 113, 169, 34, 138, 36, 186, 51, 188, 50, 186, 86, 155,
200, 85, 115, 165, 38, 101, 149, 41, 101, 138, 95, 141, 115, 171,
194, 20, 193, 21, 90, 137, 96, 144, 73, 146, 38, 102, 139, 110, 162,
32, 163, 30, 160, 89, 134, 65, 131, 89, 128, 147, 28, 90, 128, 28,
121, 145, 99, 147, 38, 100, 145}, {5, 122, 175, 3, 56, 102, 39, 105,
153, 104, 193, 43, 191, 53, 189, 57, 161, 28, 80, 117, 166, 116,
168, 39, 167, 116, 173, 40, 108, 156, 200, 49, 126, 89, 135, 34,
166, 112, 162, 89, 161, 31, 59, 103, 153, 106, 155, 191, 60, 104,
61, 124, 176, 9, 62, 125, 79, 196, 170, 39, 113, 191, 54, 161, 108,
162, 30, 60, 4, 49, 199, 87, 155, 30, 61, 123, 28, 127, 79, 122,
196, 77, 124, 36, 97, 144, 118, 169, 119, 3, 178, 42, 163, 39, 111,
161, 114, 171, 40, 172, 115, 140, 108, 198, 85, 121, 25, 119, 1, 52,
190, 59, 192, 55, 190, 19, 81, 112, 167}, {5, 63, 132, 68, 133, 28,
120, 143, 96, 139, 114, 200, 47, 180, 48, 193, 150, 42, 179, 14,
105, 139, 92, 137, 91, 134, 33, 63, 129, 29, 120, 3, 49, 188, 15,
106, 194, 57, 103, 150}, {35, 182, 76, 114, 12, 77, 195, 85, 186,
41, 111, 160, 51, 187, 33, 62, 104, 40, 100, 35, 97, 30, 154, 200,
27, 92, 134, 64, 133, 92, 138, 94, 142, 116, 165, 33, 98, 34, 94,
137, 93, 135, 88, 157, 1, 55, 189, 34, 93, 138, 108, 158, 200, 25,
115, 173, 122, 27, 119, 2, 59, 191, 51, 190, 18, 81, 123}, {16, 52,
197, 77, 105, 151, 43, 183, 45, 184, 10, 112, 190, 15, 116,
172}, {17, 88, 158, 107, 152, 105, 195, 47, 187, 44, 116, 20, 117,
28, 155, 31, 62, 127, 29, 92, 24, 109, 159, 31, 121, 76, 184, 77,
126, 28, 158, 4, 180, 6, 69, 106, 154, 29, 94, 140, 66, 102, 14, 77,
108, 197, 79, 110, 161, 22, 83, 185, 15, 80, 110, 187, 34, 190, 35,
93, 29, 151, 103, 190, 13, 180, 5, 51, 197, 24, 89, 130, 88, 199,
86, 154, 27, 111, 137, 99, 148, 40, 103, 152, 45, 180, 11, 73, 107,
156, 1, 28, 125, 29, 157, 47, 188, 8, 53, 196, 85, 153, 29, 161,
109, 199, 46, 198, 23, 108, 26, 109, 78, 122, 6, 68, 104, 21, 80,
116, 16, 77, 183, 44, 178, 1, 25, 120, 4, 61, 5, 66, 3, 59}, {17,
105, 137}, {37, 99, 138}, {23, 107, 155, 47, 189, 58, 104, 18, 55,
102, 71, 107, 157, 87, 121, 4, 156, 31, 163, 28, 91, 133, 89, 127,
80, 197, 85, 199, 54, 198, 43, 177, 2, 52, 187, 48, 181, 49, 189,
15, 79, 16, 80, 125, 16, 186, 83, 183, 8, 58, 192, 35, 98, 37, 165,
39, 103, 18, 80, 112, 82, 113, 199, 24, 90, 131, 63, 106, 72, 109,
74, 11, 72, 105, 194, 84, 118, 199}, {36, 99, 35, 65, 135, 90, 134,
30, 94, 136, 90, 26, 119, 23, 118, 200, 53, 160, 76, 110, 159, 30,
157}, {22, 88, 159, 28, 124, 47, 184, 83, 118, 1, 48, 183, 16, 81,
21, 105, 68, 131, 30, 92, 8, 178, 14, 78, 197, 48, 124, 37,
94}, {32, 132, 67, 104, 14, 80, 13, 185, 33, 90, 25, 88, 129, 89,
25, 92, 32, 93, 37, 111, 198, 47, 182, 8, 52, 188, 16, 78, 17, 54,
2, 56, 190, 17, 81}, {7, 51, 128, 63, 104, 39, 99, 38, 98}, {9, 67,
10, 176, 82, 175, 1, 47, 185, 34, 164, 113, 165, 34, 92, 26, 118,
22, 79, 13, 52, 198, 42, 171}, {5, 62, 103, 70, 106, 23, 85, 119,
31, 158, 3, 57, 190, 16}, {9, 64, 131}, {24, 107, 43, 178, 12, 76,
107, 70, 134}, {5, 30, 161, 32, 128, 29, 126, 48, 2, 53, 7, 176, 1,
26, 127, 27, 91, 132, 64, 10, 68, 11, 177, 12, 80, 23, 105, 41, 176,
2, 86, 23, 90, 20, 83, 114, 44, 108, 24, 87, 127}, {4, 29, 3, 156,
2, 85, 1, 53, 12, 179, 44, 113, 168}, {5, 50, 185, 11, 67, 5, 156,
75, 160, 110, 36, 187, 46, 186, 13, 77}, {6, 51, 200}, {21, 57, 193,
18, 102, 17, 116, 19, 82, 21, 118, 27, 109, 75, 110, 39, 169, 40,
111, 162, 31, 92, 33, 133, 69, 11, 71, 142, 95}, {24, 196}, {7, 50,
181, 7, 87}, {6, 31}, {2, 27, 93, 36, 135, 91, 24, 119}, {3,
58}, {3, 28, 160}, {15, 52, 7, 178, 9, 63, 130, 24}, {34, 97}, {34,
60}, {43, 187}, {6, 50, 2}, {43, 108}, {21, 85}, {14, 89, 26}, {6,
65, 10, 70, 132, 83}, {40, 149}, {73, 109, 43, 152}, {36, 101,
37}, {40, 112, 73}, {1, 49, 158, 75, 106}, {5, 121}, {10, 179, 45,
113, 42, 177, 10}, {40, 170}, {43, 182}, {33, 91, 35}, {46,
184}, {18, 105, 40, 175}, {42, 180, 14, 51, 194}, {56, 192}, {46,
181, 12, 101}, {19, 191}, {9, 65}, {9, 54}, {84, 186}, {19,
104}, {3, 118}, {13, 78}, {1, 155}, {71, 133}, {45, 198, 88,
128}, {30, 156}, {34, 163, 33, 161, 38}, {40, 99}, {111, 165}, {4,
176}, {9, 66}, {18, 126}, {84, 185}, {4, 179, 47}, {36, 139}, {45,
154}, {36, 112}, {51, 189}, {21, 117}, {30, 96, 34}, {32, 159}, {88,
136}, {9, 68}, {23, 91}, {13, 116}, {28, 92}, {25, 79}, {44,
115}, {15, 105}}。
一個大括弧里是其實是一條線,很難一筆走完,斷開的地方就繞圓邊走吧。
Mathematica
大概10行的樣子,按照上面朋友提供的思路。
r=50;img=ImageResize[ColorConvert[Sharpen[ImageAdd[PIC,Graphics[Disk[]]],20],"GrayScale"],{2 r,2r}];
dat=ArrayFlatten[Partition[ImageData[img],{2,2}]/.ConstantArray[0.,{2,2}]-&>{{0,1},{0,0}}];
circlepts=CirclePoints[{r+1,r+1},r-1,200]//N;
pointlist={};g=1;darkpts=RandomSample[Select[Flatten[Position[dat,#]/@Union[Select[Flatten@dat,#&
AppendTo[pointlist,pts[[Ordering[Mean/@Apply[dat[[##]],list,{2}],1]]][[1]]],{j,1,Length@darkpts}],N[Length@pointlist/60]]
Rotate[Graphics[{RGBColor[{0.1,0.1,0.1}],Thickness[10^-5],Line[pointlist//Union]}],-Pi/2]
200個點炒雞慢。
效果:
在用一行上個色(*Rotate[ImageAdd[Darker[ImageResize[PIC,{1000,1000}],.9],Graphics[Disk[]],上面的結果],-Pi/2]*)
近視的話遠看勉強有個人形,拋磚引玉啦。
要真想手工搞得話,就算條路徑,隨便一點linepts=Union[Sort/@(pointlist/.Thread[N@CirclePoints[{r+1,r+1},r-1,200][Rule]Range@200])];
h[pts_]:=
Module[{data=pts~Join~(Reverse/@pts),a={},b,pt},While[Length@data&>0,pt=data[[1]];While[Length@pt&>1,AppendTo[a,pt];data=Delete[data,Position[data,#][[1]]/@{pt,Reverse@pt}];b=Select[data,#[[1]]==pt[[2]],1];
If[Length@b==0,Break[],pt=First@b]]
];
Split[a,#1[[2]]==#2[[1]]]
]
line=h[RandomSample[linepts,Length@linepts]];
linelist=Delete[Flatten[#],Position[Differences[Flatten[#]],0]]/@line
ArcLength@Line[linelist/.Thread[Range@200-&>N@CirclePoints[0.15,200]]]
分了好幾段,也不是最短路徑,求最短路徑還要盡量段數少是炒雞麻煩的問題。
順便求個線長,200個點,半徑15cm,大概250m.
另外如果要是造個機器,機械化生產,就大概可以這樣。
比如取出上面給的那條路徑的第一段命名為list,之後
CenterPointpath[xlast_,ylast_]:=Module[{xc=xlast,yc=ylast,l1=1.5,l2=1.5},{l1 Cos[ArcTan[(l1^3 xc+l1 xc (-l2^2+xc^2+yc^2)-Sqrt[-l1^2 yc^2 (l1^4+(-l2^2+xc^2+yc^2)^2-2 l1^2 (l2^2+xc^2+yc^2))])/(l1^2 (xc^2+yc^2)),(l1^3 yc^2+l1 yc^2 (-l2^2+xc^2+yc^2)+xc Sqrt[-l1^2 yc^2 (l1^4+(-l2^2+xc^2+yc^2)^2-2 l1^2 (l2^2+xc^2+yc^2))])/(l1^2 yc (xc^2+yc^2))]],l1 Sin[ArcTan[(l1^3 xc+l1 xc (-l2^2+xc^2+yc^2)-Sqrt[-l1^2 yc^2 (l1^4+(-l2^2+xc^2+yc^2)^2-2 l1^2 (l2^2+xc^2+yc^2))])/(l1^2 (xc^2+yc^2)),(l1^3 yc^2+l1 yc^2 (-l2^2+xc^2+yc^2)+xc Sqrt[-l1^2 yc^2 (l1^4+(-l2^2+xc^2+yc^2)^2-2 l1^2 (l2^2+xc^2+yc^2))])/(l1^2 yc (xc^2+yc^2))]]}];
a={{0,0},CenterPointpath@@#,#}/@Flatten[ConstantArray[#1,5]+Table[i(#2-#1),{i,0,.9,.2}]@@@Partition[list,2,1],1]
Table[Show[ListLinePlot[a[[i]],PlotRange-&>{{-1,4},{-1,4}},AspectRatio-&>1,Axes-&>False,Mesh-&>All,MeshStyle-&>PointSize[Medium],PlotStyle-&>{Gray,Thin}],ListLinePlot[a[[1;;i,3]],PlotRange-&>{{-1,4},{-1,4}},AspectRatio-&>1,Axes-&>False,PlotStyle-&>{Black,Thin}]],{i,1,Length@a}];
Export["test.gif",%,"DisplayDurations"-&>0.005,ImageSize-&>300]
效果就是這樣http://p1.bqimg.com/1949/d4e725ffc14f577a.gif
還有http://mathematica.stackexchange.com/questions/126161/drawing-picture-with-straight-lines-petros-vrelliss-art
誰來教教我怎麼寫遺傳演算法.......這個寫法慢到狗帶......
world = 100;
chromosome = 500;
dogma = ColorNegate@Binarize@ImageResize[img, 512];
prototypes =
Partition[Partition[RandomInteger[world - 1, chromosome*16], 2],
chromosome];
(*ChromosomeToLine[{a_,b_}]:={{Sin[2.0 Pi a/world],Cos[2.0 Pi
a/world]},{Sin[2.0 Pi b/world],Cos[2.0 Pi b/world]}}*)
C2L = Compile[{{a, _Integer}, {b, _Integer}}, {{Sin[2.0 Pi a/world],
Cos[2.0 Pi a/world]}, {Sin[2.0 Pi b/world],
Cos[2.0 Pi b/world]}},
CompilationOptions -&> {"ExpressionOptimization" -&> True},
CompilationTarget -&> "C", RuntimeOptions -&> "Speed"];
C2G := Binarize@
Image[Graphics[{AbsoluteThickness[10^-5], Line /@ (C2L @@@ #)},
PlotRangePadding -&> 0], ImageSize -&> {512, 512}]
aberrance :=
Mod[(Partition[RandomInteger[#, chromosome*2], 2] /@
Floor[world Subdivide[0.2, 7]]) + ConstantArray[#, 8], world] ;
surviver :=
RandomSample[1/(1 + scores - Min[scores])^2 -&> Range[64], 8];
(*初始化迭代*)
survivers = prototypes;
Do[sons = Flatten[aberrance /@ survivers, 1];
scores = ImageDistance[C2G@#, dogma] /@ sons;
survivers = sons[[surviver]], {n, 1, 100}]
(*計算結果*)
C2G /@ survivers
推薦閱讀:
※為什麼現在手工編織毛線的特別少了,以後這種技術會不會變得更冷?
TAG:AdobePhotoshop | 平面設計 | Processing編程語言 | 編織 |