Skip to content

Small inefficiency in seamless clone init #16168

@dan-masek

Description

@dan-masek

I have just been reading through the implementation of seamless cloning, and ran across those two bits of code:

Cloning::computeGradientX

else if (img.channels() == 1)
{
Mat tmp[3];
for(int chan = 0 ; chan < 3 ; ++chan)
{
filter2D(img, tmp[chan], CV_32F, kernel);
}
merge(tmp, 3, gx);
}

Cloning::computeGradientY

else if (img.channels() == 1)
{
Mat tmp[3];
for(int chan = 0 ; chan < 3 ; ++chan)
{
filter2D(img, tmp[chan], CV_32F, kernel);
}
merge(tmp, 3, gy);
}

It appears to me that the loop calculates the same thing 3x in a row. Wouldn't it make more sense to just run filter2D once, and either merge 3 shallow copies of the result, or outright use mixChannels?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions