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;