[scikit-image] Absolute difference of images: OpenCV vs Numpy

Juan Nunez-Iglesias jni.soma at gmail.com
Thu Apr 20 23:52:12 EDT 2017


Hi Surya,

Yes, test images would be helpful. My intuition without having test data is that you have some underflow errors in the numpy call, which cv2 avoids with some preprocessing:

In [1]: im0 = np.array([64], dtype=np.uint8)

In [2]: im1 = np.array([65], dtype=np.uint8)

In [3]: np.abs(im0 - im1)
Out[3]: array([255], dtype=uint8)

This is the correct implementation in NumPy:

In [6]: np.maximum(im0, im1) - np.minimum(im0, im1)
Out[6]: array([1], dtype=uint8)

Juan.

On 21 Apr 2017, 9:12 AM +1000, Surya Kasturi <suryak at udel.edu>, wrote:
> I’m sorry,
>
> Its
>
> >> np.abs(im1 - im2)
>
>
> Surya
>
>
>
>
>
>
> > On Apr 20, 2017, at 7:10 PM, Surya Kasturi <suryak at udel.edu> wrote:
> >
> > Hey,
> >
> > I’m doing absolute difference between two images and found that the results from opencv and scikit-image are different
> >
> > >> im1 = imread(“file1.jpg”)
> > >> im2 = imread(“file2.jpg”)
> > >>
> > >> cv2.absdiff(im1, im2)
> > >> np.abs(im1, im2)
> >
> > I was expecting exactly same result.. could anyone please let me know why I’m observing slightly different results.
> >
> > (I could post images if you’d like)
> >
> > Thanks
> > Surya
> >
>
> _______________________________________________
> scikit-image mailing list
> scikit-image at python.org
> https://mail.python.org/mailman/listinfo/scikit-image
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20170421/615e0fc1/attachment.html>


More information about the scikit-image mailing list