Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv::linearPolar is the answer, but you need to set proper flags (WARP_INVERSE_MAP). Simple example below

//Set linear gradient (255 gray levels)
Mat lines(255, 255, CV_8U, Scalar(0));
for (int r = 0; r < lines.rows; r++)
namedWindow("Linear Gradient", CV_WINDOW_NORMAL);
imshow("Linear Gradient", lines);

//Convert to polar (needs WARP_INVERSE_MAP flag)
cv::linearPolar(lines, lines, cv::Point(lines.cols / 2, lines.rows / 2), 255, INTER_CUBIC | WARP_FILL_OUTLIERS | WARP_INVERSE_MAP);
namedWindow("Polar Gradient", CV_WINDOW_NORMAL);
imshow("Polar Gradient", lines);

//Mask out circle section
Mat mask(lines.size(), CV_8U, Scalar(0));
circle(mask, cv::Point(mask.cols / 2, mask.rows / 2), lines.rows/2, Scalar(255), -1);
Mat circle_gradient;
lines.copyTo(circle_gradient, mask);
namedWindow("Circle Gradient", CV_WINDOW_NORMAL);
imshow("Circle Gradient", circle_gradient);

linear gradient polar gradient circle gradient