I need to create a difference image of two images and want to have the size/length of the difference of every pixel
I'm currently doing this:
cv::Mat diff = cv::abs(img1 - img2);
cv::Mat diffLen(diff.size(), CV_32FC1);
for(int x = 0; x < diff.size().width; ++x)
for(int y = 0; y < diff.size().height; ++y)
{
float d = cv::norm(diff.at<Vec3f>(Point(x,y)));
diffLen.at<float>(Point(x,y)) = d;
}
Is there a more convenient way to do this?
I was searching for a similar purpose, and here is what I've got now:
cv::Mat diff = cv::abs(img1 - img2);
diff = diff.mul(diff);
cv::transform(diff, diff, cv::Mat::ones(1, diff.channels(), CV_32F));
cv::sqrt(diff, diff);
It's not elegant. But seems that opencv doesn't provide "pixel-wise norm" operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With