答案 0 :(得分:4)
这是一个OpenCV解决方案。基本部分是:
这是一个示例代码:
#include <opencv2\opencv.hpp>
using namespace cv;
int main()
{
// Template image
Mat3b img = imread("path_to_image");
// Create a circular mask
Mat1b mask(1000, 1000, uchar(0));
circle(mask, Point(500, 500), 500, Scalar(255), CV_FILLED);
// Or load your own mask
//Mat1b mask = imread("path_to_mask", IMREAD_GRAYSCALE)
// Compute number of repetition in x and y
int nx = (mask.cols / img.cols) + 1;
int ny = (mask.rows / img.rows) + 1;
// Create repeated pattern
Mat3b repeated = repeat(img, ny, nx);
// Crop to meet mask size
Mat3b crop = repeated(Rect(0, 0, mask.cols, mask.rows));
// Create a white image same size as mask
Mat3b result(mask.rows, mask.cols, Vec3b(255, 255, 255));
// Copy pattern with the mask
crop.copyTo(result, mask);
return 0;
}
将产生result
:
答案 1 :(得分:3)
不确定“contour”的含义,但您可以使用ImageMagick填充透明区域:
首先,制作一个圆形面具:
convert -size 500x500 xc:black -fill white -draw "circle 250,250 250,500" -colorspace gray PNG8:mask.png
现在在面具中平铺一个图案:
convert -size 500x500 tile:tomato.png mask.png -compose copyopacity -composite result.png
哦,您还可以创建一个模式,以便在直接绘制时用作填充:
convert -size 500x500 xc:white -fill tile:tomato.png -draw "circle 250,250 250,500" result.png
如果轮廓是矢量路径轮廓,您也可以这样做:
convert -size 100x100 xc:black \
-stroke yellow -strokewidth 2 -fill tile:smalltom.png \
-draw 'path "M 10 50 A 40 40 0 0 1 50 10 L 50 20 A 30 30 0 0 0 20 50 Z"' \
result.png