Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The closest I think you can do is the inpainting algorithms. They are in two places, photo and xphoto.

You would need to set the mask with non-zero pixels where it needs to be in-painted. I would suggest a width of twice what you need padded so when the white is inpainted too.

Alternatively, try doing the dilate again, but copy the original ROI into the dialated image. The copyTo function allows a mask parameter, so that's easy. The only changes would be where the dilation expanded outward.

The closest I think you can do is the inpainting algorithms. They are in two places, photo and xphoto.

You would need to set the mask with non-zero pixels where it needs to be in-painted. I would suggest a width of twice what you need padded so when the white is inpainted too.

Alternatively, try doing the dilate again, but copy the original ROI into the dialated image. The copyTo function allows a mask parameter, so that's easy. The only changes would be where the dilation expanded outward.

Edit: So, out of curiosity, if this isn't what you wanted, then what is? Can you describe what's wrong? This is the dilate with copy on a 30x30 kernel. image description

The closest I think you can do is the inpainting algorithms. They are in two places, photo and xphoto.

You would need to set the mask with non-zero pixels where it needs to be in-painted. I would suggest a width of twice what you need padded so when the white is inpainted too.

Alternatively, try doing the dilate again, but copy the original ROI into the dialated image. The copyTo function allows a mask parameter, so that's easy. The only changes would be where the dilation expanded outward.

Edit: So, out of curiosity, if this isn't what you wanted, then what is? Can you describe what's wrong? This is the dilate with copy on a 30x30 kernel. kernel.

image description

Edit2: I had an idea. How to actually accomplish this. Here's the picture:

image description

And here's the code:

Mat flower = imread("flower.png",-1);
Mat border, borderTemp;
Mat largeMask, largeFlower, largeBorder;
int padding = 30;

Mat mask;

linearPolar(flower, largeFlower, Point2f(flower.cols / 2.0, flower.rows / 2.0), 200, INTER_CUBIC);
for (int r = 0; r < largeFlower.rows; ++r)
{
    Rect petal;
    petal.y = r;
    petal.height = 1;
    petal.width = padding;
    for (int c = 0; c < largeFlower.cols; ++c)
    {
        if (largeFlower.at<Vec<uchar, 4> >(r, c)(3) == 0)
        {
            petal.x = c - padding-1;
            if (petal.x < 0)
            {
                int diff = 0 - petal.x;
                petal.x = 0;
                petal.width -= diff;
            }
            break;
        }
    }
    largeFlower(petal).copyTo(borderTemp);
    copyMakeBorder(borderTemp, border, 0, 0, 0, padding, BORDER_REFLECT);
    petal.width = border.cols;
    std::wcout << border.cols << ", " << border.rows << "\n";
    border.copyTo(largeFlower(petal));
    std::cout << r << "/" << largeFlower.rows << "\n";
}
linearPolar(largeFlower, border, Point2f(flower.cols / 2.0, flower.rows / 2.0), 200.0, INTER_CUBIC + WARP_INVERSE_MAP);

imshow("flower", flower);
imshow("border", border);
imshow("Polar", largeFlower);
imwrite("border_mirror.png", border);
waitKey();

The closest I think you can do is the inpainting algorithms. They are in two places, photo and xphoto.

You would need to set the mask with non-zero pixels where it needs to be in-painted. I would suggest a width of twice what you need padded so when the white is inpainted too.

Alternatively, try doing the dilate again, but copy the original ROI into the dialated image. The copyTo function allows a mask parameter, so that's easy. The only changes would be where the dilation expanded outward.

Edit: So, out of curiosity, if this isn't what you wanted, then what is? Can you describe what's wrong? This is the dilate with copy on a 30x30 kernel.

image description

Edit2: I had an idea. How to actually accomplish this. Here's the picture:

image description

And here's the code:

Mat flower = imread("flower.png",-1);
Mat border, borderTemp;
Mat largeMask, largeFlower, largeBorder;
int padding = 30;

Mat mask;

linearPolar(flower, largeFlower, Point2f(flower.cols / 2.0, flower.rows / 2.0), 200, INTER_CUBIC);
for (int r = 0; r < largeFlower.rows; ++r)
{
    Rect petal;
    petal.y = r;
    petal.height = 1;
    petal.width = padding;
    for (int c = 0; c < largeFlower.cols; ++c)
    {
        if (largeFlower.at<Vec<uchar, 4> >(r, c)(3) == 0)
        {
            petal.x = c - padding-1;
            if (petal.x < 0)
            {
                int diff = 0 - petal.x;
                petal.x = 0;
                petal.width -= diff;
            }
            break;
        }
    }
    largeFlower(petal).copyTo(borderTemp);
    copyMakeBorder(borderTemp, border, 0, 0, 0, padding, BORDER_REFLECT);
    petal.width = border.cols;
    std::wcout << border.cols << ", " << border.rows << "\n";
    border.copyTo(largeFlower(petal));
    std::cout << r << "/" << largeFlower.rows << "\n";
}
linearPolar(largeFlower, border, Point2f(flower.cols / 2.0, flower.rows / 2.0), 200.0, INTER_CUBIC + WARP_INVERSE_MAP);

imshow("flower", flower);
imshow("border", border);
imshow("Polar", largeFlower);
imwrite("border_mirror.png", border);
waitKey();

The closest I think you can do is the inpainting algorithms. They are in two places, photo and xphoto.

You would need to set the mask with non-zero pixels where it needs to be in-painted. I would suggest a width of twice what you need padded so when the white is inpainted too.

Alternatively, try doing the dilate again, but copy the original ROI into the dialated image. The copyTo function allows a mask parameter, so that's easy. The only changes would be where the dilation expanded outward.

Edit: So, out of curiosity, if this isn't what you wanted, then what is? Can you describe what's wrong? This is the dilate with copy on a 30x30 kernel.

image description

Edit2: I had an idea. How to actually accomplish this. Here's the picture:

image description

And here's the code:

Mat flower = imread("flower.png",-1);
Mat border, borderTemp;
Mat largeMask, largeFlower, largeBorder;
int padding = 30;

Mat mask;

linearPolar(flower, largeFlower, Point2f(flower.cols / 2.0, flower.rows / 2.0), 200, INTER_CUBIC);

//Handle the fuzzy alpha boundary.
extractChannel(largeFlower, largeMask, 3);
erode(largeMask, largeMask, Mat());
insertChannel(largeMask, largeFlower, 3);

for (int r = 0; r < largeFlower.rows; ++r)
{
    Rect petal;
    petal.y = r;
    petal.height = 1;
    petal.width = padding;
    for (int c = 0; c < largeFlower.cols; ++c)
    {
        if (largeFlower.at<Vec<uchar, 4> >(r, c)(3) == 0)
        {
            petal.x = c - padding-1;
            if (petal.x < 0)
            {
                int diff = 0 - petal.x;
                petal.x = 0;
                petal.width -= diff;
            }
            break;
        }
    }
    largeFlower(petal).copyTo(borderTemp);
    copyMakeBorder(borderTemp, border, 0, 0, 0, padding, BORDER_REFLECT);
    petal.width = border.cols;
    border.copyTo(largeFlower(petal));
}
linearPolar(largeFlower, border, Point2f(flower.cols / 2.0, flower.rows / 2.0), 200.0, INTER_CUBIC + WARP_INVERSE_MAP);

imshow("flower", flower);
imshow("border", border);
imshow("Polar", largeFlower);
imwrite("border_mirror.png", border);
waitKey();