mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 03:00:14 +08:00
Merge pull request #25402 from Linaname:4.x
Handle top and left border masked pixels correctly in inpaint method #25402 Fixes #25389 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
parent
f9dd20eb07
commit
37ca0308a7
@ -340,7 +340,7 @@ icvTeleaInpaintFMM(const CvMat *f, CvMat *t, CvMat *out, int range, CvPriorityQu
|
||||
gradI.y=0;
|
||||
}
|
||||
}
|
||||
Ia[color] += (float)w * (float)(CV_MAT_3COLOR_ELEM(*out,uchar,km,lm,color));
|
||||
Ia[color] += (float)w * (float)(CV_MAT_3COLOR_ELEM(*out,uchar,k-1,l-1,color));
|
||||
Jx[color] -= (float)w * (float)(gradI.x*r.x);
|
||||
Jy[color] -= (float)w * (float)(gradI.y*r.y);
|
||||
s[color] += w;
|
||||
@ -452,7 +452,7 @@ icvTeleaInpaintFMM(const CvMat *f, CvMat *t, CvMat *out, int range, CvPriorityQu
|
||||
gradI.y=0;
|
||||
}
|
||||
}
|
||||
Ia += (float)w * (float)(CV_MAT_ELEM(*out,data_type,km,lm));
|
||||
Ia += (float)w * (float)(CV_MAT_ELEM(*out,data_type,k-1,l-1));
|
||||
Jx -= (float)w * (float)(gradI.x*r.x);
|
||||
Jy -= (float)w * (float)(gradI.y*r.y);
|
||||
s += w;
|
||||
@ -555,7 +555,7 @@ icvNSInpaintFMM(const CvMat *f, CvMat *t, CvMat *out, int range, CvPriorityQueue
|
||||
dir = (float)fabs(VectorScalMult(r,gradI)/sqrt(VectorLength(r)*VectorLength(gradI)));
|
||||
}
|
||||
w = dst*dir;
|
||||
Ia[color] += (float)w * (float)(CV_MAT_3COLOR_ELEM(*out,uchar,km,lm,color));
|
||||
Ia[color] += (float)w * (float)(CV_MAT_3COLOR_ELEM(*out,uchar,k-1,l-1,color));
|
||||
s[color] += w;
|
||||
}
|
||||
}
|
||||
@ -645,7 +645,7 @@ icvNSInpaintFMM(const CvMat *f, CvMat *t, CvMat *out, int range, CvPriorityQueue
|
||||
dir = (float)fabs(VectorScalMult(r,gradI)/sqrt(VectorLength(r)*VectorLength(gradI)));
|
||||
}
|
||||
w = dst*dir;
|
||||
Ia += (float)w * (float)(CV_MAT_ELEM(*out,data_type,km,lm));
|
||||
Ia += (float)w * (float)(CV_MAT_ELEM(*out,data_type,k-1,l-1));
|
||||
s += w;
|
||||
}
|
||||
}
|
||||
|
@ -157,4 +157,30 @@ TEST(Photo_InpaintBorders, regression)
|
||||
ASSERT_TRUE(countNonZero(diff) == 0);
|
||||
}
|
||||
|
||||
typedef testing::TestWithParam<tuple<perf::MatType>> Photo_InpaintSmallBorders;
|
||||
|
||||
TEST_P(Photo_InpaintSmallBorders, regression)
|
||||
{
|
||||
int type = get<0>(GetParam());
|
||||
Mat img(5, 5, type, Scalar::all(128));
|
||||
Mat expected = img.clone();
|
||||
|
||||
Mat mask = Mat::zeros(5, 5, CV_8U);
|
||||
mask(Rect(1, 1, 3, 3)) = 255;
|
||||
|
||||
img.setTo(Scalar::all(0), mask);
|
||||
|
||||
Mat inpainted, diff;
|
||||
|
||||
inpaint(img, mask, inpainted, 1, INPAINT_TELEA);
|
||||
cv::absdiff(inpainted, expected, diff);
|
||||
ASSERT_EQ(countNonZero(diff.reshape(1)), 0);
|
||||
|
||||
inpaint(img, mask, inpainted, 1, INPAINT_NS);
|
||||
cv::absdiff(inpainted, expected, diff);
|
||||
ASSERT_EQ(countNonZero(diff.reshape(1)), 0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Photo_InpaintSmallBorders, Values(CV_8UC1, CV_8UC3));
|
||||
|
||||
}} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user