Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
43 Views

How to copy the image border efficiently ?

Jump to solution

Hi

Suppose I have a imageA, now I want it have the duplicate border, for example, copy the data from the second row to the first row, copy the data from the last but one row to the last row, copy the second column to the first colum, copy the last but one column to the last colum.

In opencv, it is very simple

        image.row(1).copyTo(image.row(0));//copy 2nd row to first row
        image.row(nx).copyTo(image.row(nx+1));//copy last but one row to the last row
        image.col(1).copyTo(image.col(0)); //copy last but one column to the last column
        image.col(ny).copyTo(image.col(ny+1));//copy last but one column to the last column

So I dont knwo if there is a efficient way to do same thing using IPP ?

Thanks !

Stella

0 Kudos

Accepted Solutions
Highlighted
Employee
43 Views

Hi Stella,

I believe more proper way to make border in OpenCV is like this:

    cv::Mat srcSub = cv::Mat(src, cv::Rect(1, 1, src.size().width - 2, src.size().height - 2)); // Create submatrix which points to image inside border
    cv::copyMakeBorder(srcSub, src, 1, 1, 1, 1, BORDER_REPLICATE);

In IPP there are similar functions, e.g.:

    IppiSize srcSize = {width-2, height-2}; // Size of image inside border
    IppiSize dstSize = {width, height}; // Full size with border
    pSrc = (Ipp8u*)pSrc + srcDstStep + elemSize; // Shift pointer to be inside border
    ippiCopyReplicateBorder_8u_C1IR_L(pSrc, srcDstStep, srcSize, dstSize, 1, 1);

This will replicate border rows/columns in the same image. This example is for 8u C1 data with 1px border for every side.

View solution in original post

0 Kudos
2 Replies
Highlighted
Employee
44 Views

Hi Stella,

I believe more proper way to make border in OpenCV is like this:

    cv::Mat srcSub = cv::Mat(src, cv::Rect(1, 1, src.size().width - 2, src.size().height - 2)); // Create submatrix which points to image inside border
    cv::copyMakeBorder(srcSub, src, 1, 1, 1, 1, BORDER_REPLICATE);

In IPP there are similar functions, e.g.:

    IppiSize srcSize = {width-2, height-2}; // Size of image inside border
    IppiSize dstSize = {width, height}; // Full size with border
    pSrc = (Ipp8u*)pSrc + srcDstStep + elemSize; // Shift pointer to be inside border
    ippiCopyReplicateBorder_8u_C1IR_L(pSrc, srcDstStep, srcSize, dstSize, 1, 1);

This will replicate border rows/columns in the same image. This example is for 8u C1 data with 1px border for every side.

View solution in original post

0 Kudos
Highlighted
Beginner
43 Views

Hi Pavel,

Thanks for your reply. I believe you give me the correct answer.

I will try then.

Thanks,

Stella

 

Pavel V. (Intel) wrote:

Hi Stella,

I believe more proper way to make border in OpenCV is like this:

    cv::Mat srcSub = cv::Mat(src, cv::Rect(1, 1, src.size().width - 2, src.size().height - 2)); // Create submatrix which points to image inside border
    cv::copyMakeBorder(srcSub, src, 1, 1, 1, 1, BORDER_REPLICATE);

In IPP there are similar functions, e.g.:

    IppiSize srcSize = {width-2, height-2}; // Size of image inside border
    IppiSize dstSize = {width, height}; // Full size with border
    pSrc = (Ipp8u*)pSrc + srcDstStep + elemSize; // Shift pointer to be inside border
    ippiCopyReplicateBorder_8u_C1IR_L(pSrc, srcDstStep, srcSize, dstSize, 1, 1);

This will replicate border rows/columns in the same image. This example is for 8u C1 data with 1px border for every side.

0 Kudos