Interactive Digital Photomontage:http://grail.cs.washington.edu/projects/photomontage/
GCOv3.0工具包的具體使用方法:https://blog.csdn.net/jzwong/article/details/69947711
上面這個博客講的使用方法是單張圖像的分割方法,然而在photomontage中,需要的是從多張圖片中選取合適的部分最終拼接到一塊,再通過梯度域融合,使接縫不明顯。
在這裏只講如何使用GCOv3.0工具包達到多幅圖片拼接的過程。
選取一張作爲背景圖A,然後從多個圖像中選取一個圖像B。
初始化標籤,即人工的選出B中較好的想要取代A中的區域的部分。這一部分稱爲B標籤,其餘部分稱爲A標籤。
將這兩幅圖當作標籤,計算datacost(像素自身特徵)
和smoothcost(相鄰像素對在兩個標籤中的距離)
進行alpha-expansion 即最小割。計算最適合切割的地方。
Potts_K = 200;
datacost = calcdatacost(weightG,weightL,h*w);
neighbours = Potts_K*calcneighbours(input,background,h,w);
SmoothCost = eye(2);
SmoothCost = 1 - SmoothCost;
small=min(min(Label));
big=max(max(Label));
Label(Label==small)=1;
Label(Label==big)=2;
init_lable=reshape(Label,[h*w 1]);
hist = GCO_Create(h*w,2);
GCO_SetLabeling(hist,init_lable);
GCO_SetDataCost(hist,datacost');
GCO_SetSmoothCost(hist,SmoothCost);
GCO_SetNeighbors(hist,neighbours);
GCO_SetVerbosity(hist,2);
GCO_Expansion(hist);
Labeling = GCO_GetLabeling(hist);
GCO_Delete(hist);
Labeling(Labeling==1)=small;
Labeling(Labeling==2)=big;